Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I bypass the same-origin policy of an iframe for Chrome extensions?
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/11325415/access-iframe-content-from-a-chromes-extension-content-script">access iframe content from a chrome&#39;s extension content script</a> </p> </blockquote> <p>I'm trying to manipulate part of an iframe on a webpage via a Chrome extension.</p> <p>Everytime I do, I get a "Unsafe JavaScript attempt to access frame with URL" error. <a href="http://developer.chrome.com/extensions/xhr.html#requesting-permission" rel="nofollow noreferrer">Reading the Chrome extension documentation, it appears I should be able to ask for permissions</a> to do this in my manifest.json. But nothing I've done seems to allow me to do this.</p> <p>My manifest.json:</p> <pre><code>{ "name": "Manipulate an iframe", "description": "Test to manipulate an iframe", "version": "1.0", "background": { "scripts": ["background.js"] }, "permissions": [ "tabs", "http://*/", "https://*/", "&lt;all_urls&gt;" ], "browser_action": { "name": "Modify iframe", "icons": ["icon.png"] }, "manifest_version": 2 } </code></pre> <p>My background.js:</p> <pre><code>chrome.browserAction.onClicked.addListener(function(tab) { chrome.tabs.executeScript(null, { allFrames:true, runAt:"document_end", file: "jquery-latest.min.js" }, function() { chrome.tabs.executeScript(null, { allFrames:true, runAt:"document_end", file: "content-script.js" }); }); }); </code></pre> <p>My content-script.js:</p> <pre><code>$('.container').css('width','98%'); $('#myPage iframe').contents().find('#code').unwrap() </code></pre> <p>The container is resized correctly when I click the extension button, but I can't touch the iframe. It seems to me that I've given all the permissions I can, so is there somewhere else I need to specify permissions?</p> <p>Edit :</p> <p>I found this answer to be helpful in understanding the different types of scripts in a Chrome extension: <a href="https://stackoverflow.com/a/9916089/1698152">https://stackoverflow.com/a/9916089/1698152</a></p> <p>The flagged duplicate answer: <a href="https://stackoverflow.com/questions/11325415/access-iframe-content-from-a-chromes-extension-content-script">access iframe content from a chrome&#39;s extension content script</a> was sufficient to answer my question.</p> <p>Instead of trying to inject into all frames via tabs.executeScript, I injected content scripts into all frames by defining them in the manifest. I was then able to call functions in these scripts from the background page script via message passing.</p> <p>I still don't understand why this is any different from what I was already doing, however.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload