I am currently working on creating a WebExtension using Angular and Ionic. The extension successfully loads the application and enables communication between Content Script and Background Script. However, I am facing an issue where the TypeScript code is not being interpreted correctly, leading to difficulties in storing data in the application variables. My goal is to extract webpage content into my Angular application. Is this technically feasible? Any assistance would be greatly appreciated. Thank you for your help.
manifest.json :
{
"manifest_version": 2,
//[...]
"background": {
"page": "index.html#/background"
},
"content_scripts":
[{
"matches" : ["<all_urls>"],
"js": ["content_script.js"]
}]
}
content_script.js :
browser.runtime.sendMessage({url: location.href});
Background Script (Angular) :
ngOnInit() {
var browser = browser || chrome;
browser.runtime.onMessage.addListener(this.showMessage);
}
public url: string;
showMessage(message) {
alert(message.url); // This works
this.url = message.url;
alert(this.url); // This does not work
}