In a geckoview based app I need to display various errors in the browser window. Some of the buttons offered there have to be evaluated and processed further in the app.
I have tried various scenarios and have come to the conclusion that in order to be able to transfer information from the web page script to the app, I need to build a web extension with content script and background script.
That's why I wrote a WebExtension in which a web page script evaluates the click on the web button and forwards this information to the content script via window.postMessage(), which then forwards the information to the background script via sendMessage() (and this can send the data to the app via sendNativeMessage()).
My Extension works fine on a Firefox on PC where I can see the messages. But when I install it in my Android app (based on geckoview), the content_script does not start.
My manifest contains (amongst others) this:
“content_scripts”: [
{
“matches”: [“file:///*” , “<all_urls>”],
“js”: [“content.js”]
}
],
“permissions”: [
“nativeMessaging”,
“activeTab”,
“storage”,
“webRequest”,
“<all_urls>”
]
The content script starts with the borderfy example to see whether the context script is executed or not:
document.body.style.border = “5px solid red”;
console.info(“Content Script!”);
When I load a normal web page (e.g. https://mozilla.com), the script is started (I see the red boarders).
Originally, I started the HTML file from resource but acording to “https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Match_patterns” a pattern “resource://path/” is invalid. (The HTML page is currently not part of the webExtension.)
That’s why I added “file:///*” for content_script matches to the manifest and copied the HTML file to the local cache (and later to the download folder for testing) - but always the same: the content script does not start.