I have been working in my free time to create a Firefox WebExtensions based add-on that essentially reads the page, opens a local HTML, submits a form on the HTML page to navigate to a new URL but I am running into issues with chrome.extension.getViews()
once my opened page changes URLs.
If I reuse getViews()
I receive the following error:
Not allowed to define cross-origin object as property on [Object] or [Array] XrayWrapper
I tracked this down and find it happens once my local HTML navigates away. How should I be interacting with my opened web page to get around this issue?
Below is a small recreation I hacked together with timeouts (not my actual project, just to show the problem):
background.js
var views;
function openMyPage() {
console.log("injecting");
chrome.tabs.create({
url: chrome.extension.getURL("content_scripts/my-page.html"),
active: false
}, function(tab) {
chrome.windows.create({
tabId: tab.id,
type: "normal",
state: "maximized"
}, function(window) {
setTimeout(function(){
views = chrome.extension.getViews();
for(var i = 0; i < views.length; i++)
console.log("window location: " + views[i].location + " view id: " + i);
views[1].example();
setTimeout(function(){
for(var i = 0; i < views.length; i++)
console.log("window location: "+views[i].location+" view id: " + i);
}, 5000);
}, 2000);
});
});
}
chrome.browserAction.onClicked.addListener(openMyPage);
my-page.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="my-page.js"></script>
</head>
<body>
<h1>It's my page!</h1>
</body>
</html>
my-page.js
console.log("loaded in my-page");
function example() {
document.location.href = "https://www.google.com/";
}