I'm trying to implement a noddy web extension for GeckoView in Android to simply execute some javascript on a web page, the equivalent of webView.evaluateJavascript() on a normal Android WebView, however I'm having trouble finding any useful examples or tutorials online.
I have previously tried a WebView before, however the site I am attempting to access bugs during login meaning I cannot access it. However the login works with a GeckoView
I've followed these so far:
https://sammacbeth.eu/blog/2019/09/04/geckoview-extensions.html
https://mozilla.github.io/geckoview/consumer/docs/web-extensions
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Your_first_WebExtension
However, they seem to be a bit dated, even mozilla's own documentation, as the API I am using no longer follows the examples.
I'm using the stable release of GeckoView: 73.0.20200217142647
As per [3] above, my file structure is:
java
|
+-- assets
| |
| +--checkExtension
| |
| manifest.json
| checkExtension.js
|
+-- res
|
+-- src
The contents of manifest.json is
{
"manifest_version": 2,
"name": "checkExtension",
"version": "1.0",
"description": "Automatically clicks the authorise button to continue the photo upload.",
"content_scripts": [
{
"matches": ["*"],
"js": ["checkExtension.js"]
}
],
"permissions": [
"nativeMessaging",
"geckoViewAddons"
]
}
'matches' is set to '*' so that it should match any and all pages navigated to
checkExtension.js just contains:
alert('hello')
My GeckoView activity is:
GeckoView view = findViewById(R.id.geckoview);
GeckoSession session = new GeckoSession();
GeckoRuntime runtime = GeckoRuntime.create(this);
session.open(runtime);
WebExtension test = new WebExtension(
"resource://assets/extension/checkExtension/",
runtime.getWebExtensionController());
runtime.registerWebExtension(test);
view.setSession(session);
session.loadUri("https://www.google.com");
However, no alert is showing when the page loads. I have tried a few site-specific targeted scripts besides just attempting to show an alert box, however none of them have worked either.
Is there anything obvious is am missing or any resources that might help me?
Many Thanks.