{"id":19034504,"url":"https://github.com/shannah/webviewjar","last_synced_at":"2025-04-23T17:46:31.332Z","repository":{"id":50439454,"uuid":"226397723","full_name":"shannah/webviewjar","owner":"shannah","description":"Java port of the Zserge Webview.  Tiny cross-platform WebView","archived":false,"fork":false,"pushed_at":"2021-04-29T22:47:19.000Z","size":5561,"stargazers_count":91,"open_issues_count":6,"forks_count":15,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T08:09:20.662Z","etag":null,"topics":["chromium","edge","java","ui","webkit","webview"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shannah.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-06T19:43:39.000Z","updated_at":"2025-02-08T12:54:17.000Z","dependencies_parsed_at":"2022-08-12T21:20:53.976Z","dependency_job_id":null,"html_url":"https://github.com/shannah/webviewjar","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shannah%2Fwebviewjar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shannah%2Fwebviewjar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shannah%2Fwebviewjar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shannah%2Fwebviewjar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shannah","download_url":"https://codeload.github.com/shannah/webviewjar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249348673,"owners_count":21255300,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chromium","edge","java","ui","webkit","webview"],"created_at":"2024-11-08T21:45:34.513Z","updated_at":"2025-04-17T14:32:36.850Z","avatar_url":"https://github.com/shannah.png","language":"C","readme":"# WebView\n\nThis is a Java port of the fantastic, tiny, light-weight [WebView](https://github.com/zserge/webview) by [Serge Zaitsev](https://zserge.com).\n\nIt is packaged into an executable Jar file so that you can run it as a CLI self-contained process or as a Java library inside your current process.\n\n## Synopsis\n\nCross-platform WebView that can be opened and controlled via CLI or as JavaAPI.\n\n## Installation\n\nDownload [WebView.jar](bin/WebView.jar)\n\nThis jar can be run directly as an executable jar file (e.g. `java -jar WebView.jar [OPTIONS]`), or using the Java API by adding the jar to your classpath.\n\n## Platform Support\n\nRuns on Windows (32 or 64), Linux (64), and Mac.  Other platforms (e.g. Linux 32) can be supported.  Simply need to build the native libs for that platform.\n\n## Running in Separate Process\n\n\nYou can run the WebView in a separate process by running:\n\n~~~~\n$ java -jar WebView.jar http://www.example.com\n~~~~\n\nThis will open the web browser in its own window pointing to http://www.example.com.\n\n**CLI Usage Instructions**\n\n~~~~\nUsage: java -jar WebView.jar [OPTIONS] \u003curl\u003e\n\n  \u003curl\u003e - A URL to a webpage to show in the webview.  \nNote: You can use a data url here.\n\nOptions:\n  -title \u003cWindow Title\u003e\n  -w \u003cwindow width px\u003e\n  -h \u003cwindow height px\u003e\n  -onLoad \u003cjs to run on page load\u003e\n  -onLoadFile \u003cpath to js file to run on page load\u003e\n  -useMessageBoundaries    Use message boundaries for wrapping messages from the webview.   Makes it easier to parse.\n\nExamples:\n\njava -jar WebView.jar https://example.com\n  Opens webview with starting page https://example.com\n\njava -jar WebView.jar \"data:text/html,%3Chtml%3Ehello%3C%2Fhtml%3E\"\n  Opens webview that says 'hello html'\n\njava -jar WebView.jar https://google.com \\\n   -onLoad \"window.addEventListener('load', function(){postMessageExt('loaded '+location.href)})\"\n  Opens a webview, and prints out URL of each page on window load event.\n~~~~\n\n### Interacting with the Browser Environment\n\nYou can interact with the browser environment by typing into the console while the browser is running.  The browser listens on STDIN, for any input, and it will evaluate any input as Javascript in the context of the current page.  E.g. Type \"alert('foo')\" then `[ENTER]` to open an alert popup.  \n\nIf you need to enter a multi-line Javascript command, then begin your input with `\u003c\u003c\u003cSOME_BOUNDARY`, and end it with `SOME_BOUNDARY`.\n\nFor example:\n\n~~~~\n\u003c\u003c\u003cEND\nvar url = window.location.href;\nalert('You are at '+url);\nEND\n~~~~\n\nNOTE:  If you give it an empty boundary, then it will simply use a blank line as your boundary.\n\n### Getting Information From The Browser\n\nThere are two ways get the browser to communicate back to the outside world:\n\n1. The onLoad callback.  Whenever the user nagivates to a new page, it will output `loaded [URL]` to STDOUT.  E.g. If you navigate to google.com, then it will output `loaded https://google.com` to STDOUT.\n2. Call `window.postMessageExt(\"some message\")`.  This will cause the browser print \"some message\" to STDOUT.  All messages of this kind are wrapped with beginning and ending boundaries to make the output easier to parse, in case you are writing a program to interact with the browser.\n\nHere is an example of a session, where I load google.com, and then get its page title via `window.external.invoke()`:\n\n~~~~\n$ java -jar WebView-shaded.jar \"https://www.google.com\"\n\nloaded https://www.google.com/\nwindow.external.invoke(document.title)\n\u003c\u003c\u003cBoundary1575660241187\nGoogle\nBoundary1575660241187\n~~~~\n\nA few things to notice here:\n\n1. When the page is loaded, it informed us with \"loaded https://www.google.com\" in STDOUT\n2. I typed the \"window.external.invoke(document.title)\" command.\n3. It responded to my command with an open boundary `\u003c\u003c\u003cBoundary1575660241187` followed by the message (\"Google\"), followed by the closing boundary `Boundary1575660241187`\n\n## Using Java API\n\nIf you want to use the webview directly in your Java app, you can do this also. \n\nA simple usage example:\n\n~~~~\nwebview = new WebView()\n    .size(width, height)\n    .title(title)\n    .resizable(resizable)\n    .fullscreen(fullscreen)\n    .url(u)\n    .onLoad(()-\u003e{\n       //.. Do something on page load.\n\t   // You can get the url of the page via webview.url()\n    })\n    .javascriptCallback(message-\u003e{\n        // Handle a message sent via window.external.invoke(message)\n        // message is a string.\n    })\n    .show();\n~~~~\n\nNOTE: The `show()` method will start a blocking event loop.\n\nWARNING: Currently the WebView is picky about being started on the main application thread.  On Mac you may need to add the \"-XstartOnFirstThread\" flag in the JVM.\n\n## Using Java API from Swing, JavaFX, or other UI Toolkit\n\nThe WebView class cannot be used from Swing, JavaFX, or any other existing UI toolkit because it starts its own event loop.  If you want to make use of the WebView from within such an app, you'll need to use the WebViewCLIClient class, which provides an interface to create and manage a WebView which runs inside its own subprocess.\n\nSee the [Swing Demo](demos/WebViewSwingDemo/README.md) for a full example of this.\n\nThe basics are:\n\n~~~~\n\n// Opening the webview\nWebViewCLIClient webview = (WebViewCLIClient)new WebViewCLIClient.Builder()\n    .url(\"https://www.codenameone.com\")\n    .title(\"Codename One\")\n    .size(800, 600)\n    .build();\n    \n// Adding a load listener (fired whenever a page loads)\nwebview.addLoadListener(evt-\u003e{\n    System.out.println(\"Loaded \"+evt.getURL());\n});\n\n// Adding a message listener (fired whenever any js calls window.postMessageExt(msg))\nwebview.addMessageListener(evt-\u003e{\n    System.out.println(evt.getMessage());\n});\n\n// Evaluate javascript on the current page.  Implicit callback() method\n// allows you to return result in CompetableFuture.\nwebview.eval(\"callback(window.location.href)\")\n    .thenAccept(str-\u003e{\n        System.out.println(\"Current URL is \"+str);\n    });\n    \n    \n\n    \n// Closing the webview later\nwebview.close();\n~~~~\n\n\n    \n\n\n#### Demos\n\n1. [Swing Demo](demos/WebViewSwingDemo/README.md) - A simple demo showing how to create and control a WebView from a Swing App.\n2. [Minimal Demo](demos/WebViewMinimalDemo/README.md) - A simple demo that only launches a WebView on the main thread.\n\n## Supported Platforms\n\nThis should work on Mac, Linux, and Windows.\n\n\n## Building Sources\n\n~~~\ngit clone https://github.com/shannah/webviewjar\ncd webviewjar\nant jar\n~~~\n\nThis will create dist/WebView.jar, which can be run as an executable jar.\n\n### Troubleshooting\n\nANT requires that the `platforms.JDK_1.8.home` system property is set to your JAVA_HOME.  If it complains about this, you can fix the issue by changing the `ant jar` command, above, to `ant jar -Dplatforms.JDK_1.8.home=\"$JAVA_HOME\"`.\n\n### Rebuilding Native Libs\n\nThe repo comes with pre-built native libs in the src/windows_32, src/windows_64, src/osx_64, and src/linux_64.  If you want to make changes to these native libs, then the following information may be of use to you.\n\n1. Use the `build-xxx.sh` (where xxx is your current platform) scripts to rebuild the native sources, and copy them into the appropriate place in the src directory.\n2. Mac and linux native sources are located in the src_c directory.  Windows native sources are in the windows directory.\n3. On Windows, you'll need to have Visual Studio installed (I use VS 2019, but earlier versions probably work).  Additionally, I use git bash on Windows, which is why the build-windows.sh is a bash script, and not a .bat script.\n\n\n\n## License\n\nMIT\n\n## Credits\n\n1. This library created by [Steve Hannah](https://sjhannah.com)\n2. Original webview library by [Serge Zaitsev](https://zserge.com)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshannah%2Fwebviewjar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshannah%2Fwebviewjar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshannah%2Fwebviewjar/lists"}