I am developing a chrome extension when user clicked on the browser action button, a new tab should have to open there the screen should be splitted using frames. Inside the frames i have text box as well as iframe. The text box will acts like url bar, when the user enters the url in text box, i will update the content of iframe.
Here comes my actual problem, when the user clicks on any link inside the iframe, i have to update the url bar, but i can’t able to add event listener for the links that are inside the iframe, the problem is i can’t able to access the element inside the iframe, i am getting error as “Unsafe javascript attempt to access URL …… from the frame ….”.
This page is chrome extension tab, if it is other page, i could inject content script to add event listener inside frame, so i can’t use the content script here.
Things that i tried but didn’t work:
i) In manifest.json i added permission as “permissions”: [
“tabs”,
“http:///“,
“https:///”
]
but didn’t work.
ii) tried –allow-file-access-from-files in chrome browser but didn’t work
You don’t need to inject scripts into html files inside the extension. From those, you’ll be able to access the chrome.* API from page scripts.
That being said, if the iframe and the frame with the textbox are in different domains, you cannot access one from the other, since cross-site scripting security prevents it.
I’d need to see more of the HTML file you already have, but you might be able to do something like this…
In the extension tab (that contains the text box):
In the background page:
Finally, a content script to be run on
http://*andhttps://*. Make sure that you have this in your manifest (add it to an existing list of content scripts):It is important that you have the
all_framesset totrueto get the script to run inside the iframe.Then, you’d have this in
address.js:Basically, the
window.topcheck should avoid confusion by only sending the url update message from inside iframes. You might need more filtering to keep it from running on other pages you don’t want it to.This is untested, but I’m fairly confident that this kind of solution would work.