I want to use GeckoView
in my project. But I need to run some Javascript code in this project. How can I achieve this?
Asked
Active
Viewed 2,036 times
4

HF_
- 689
- 3
- 9
- 22

DummytoDummy
- 553
- 1
- 5
- 13
-
What do you mean by "inject javascript"? Can you provide an example of your use-case? – Dexter Jul 30 '19 at 07:53
-
1Something like this : https://medium.com/appunite-edu-collection/webview-with-injected-js-script-13eb1e0257c9 – DummytoDummy Jul 31 '19 at 11:17
1 Answers
3
One possible way could be to use the GeckoSession.loadUri
API to inject the JavaScript code
loadUri("javascript:{js_code}")
This used to work, I'm not sure it works any longer :)
Edit - another option would be to create a WebExtension to interact with content. GeckoView has some documentation here. You should be able to declare a content script file name in the extension's manifest and bundle the content script with your extension.

Dexter
- 2,482
- 27
- 40
-
-
I've slightly tweaked my answer to provide a second option, let me know if that works. – Dexter Aug 08 '19 at 07:34
-
1Really thanks for your effort, I appreciate that. I've searched WebExtensions too. I think WebExtensions are used to run .js files from resource but I want to work with javascript in the loaded page. So WebExtension won't work for my case, was it? – DummytoDummy Aug 08 '19 at 07:41