4

I want to use GeckoView in my project. But I need to run some Javascript code in this project. How can I achieve this?

HF_
  • 689
  • 3
  • 9
  • 22
DummytoDummy
  • 553
  • 1
  • 5
  • 13

1 Answers1

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
  • nope, it's not working for us. I'm still searching. – DummytoDummy Aug 08 '19 at 07:14
  • I've slightly tweaked my answer to provide a second option, let me know if that works. – Dexter Aug 08 '19 at 07:34
  • 1
    Really 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