Skip to content

Commit 5f0ea91

Browse files
authored
Add ability to copy text in the embedded browser (#8588)
1 parent fb28a61 commit 5f0ea91

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/io/flutter/jxbrowser/EmbeddedJxBrowser.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import com.teamdev.jxbrowser.browser.event.ConsoleMessageReceived;
1818
import com.teamdev.jxbrowser.engine.Engine;
1919
import com.teamdev.jxbrowser.js.ConsoleMessage;
20+
import com.teamdev.jxbrowser.permission.PermissionType;
21+
import com.teamdev.jxbrowser.permission.callback.RequestPermissionCallback;
2022
import com.teamdev.jxbrowser.ui.KeyCode;
2123
import com.teamdev.jxbrowser.ui.event.KeyPressed;
2224
import com.teamdev.jxbrowser.view.swing.BrowserView;
@@ -56,6 +58,18 @@ public EmbeddedJxBrowserTab(Engine engine) {
5658
this.engine = engine;
5759

5860
try {
61+
// Support copying text in the embedded browser to the clipboard. The following was copied from:
62+
// https://teamdev.com/jxbrowser/docs/guides/clipboard/#necessary-permissions
63+
this.engine.permissions().set(RequestPermissionCallback.class, (params, tell) -> {
64+
var type = params.permissionType();
65+
if (type == PermissionType.CLIPBOARD_READ_WRITE
66+
|| type == PermissionType.CLIPBOARD_SANITIZED_WRITE) {
67+
tell.grant();
68+
} else {
69+
tell.deny();
70+
}
71+
});
72+
5973
this.browser = engine.newBrowser();
6074
this.zoom = this.browser.zoom();
6175
this.browser.settings().enableTransparentBackground();

0 commit comments

Comments
 (0)