0

I'm aware that you are able to load external domains in iFrames in Chrome Extensions by specifying their permissions in the manifest, and using content_scripts with all_frames to inject your own code.

However, I am now using optional_permissions to avoid user prompts on install, and opted to instead prompt when the user actual needs said permission. The idea is to load a content script inside an iFrame of specific pages. What I did before was run the content script on all pages, but use a #hash to specify when to run frame specific code.

Now that I only use optional_permissions, how do I go about actually getting the script to run inside the iFrame?

Basically I want something like this in my main window.

on userAction {
    loadFrame(externalURL); // This I can do just fine.
    loadContentScriptinFrame(); // How do I do this?
}

Or is there some manifest trickery that works with a combination of content_scripts, optional_permissions, all_frames, and if(frame){doStuff()} ?

Thirk
  • 571
  • 1
  • 7
  • 24
  • You can use content script declaring with optional permissions. Make sure that the optional permissions are only declared in "optional_permissions", and not in "permissions" or in "content_scripts[*].matches". Use the "chrome.declarativeContent.RequestContentScript" action to insert a content script in the page. See the reference for more details about the API: https://developer.chrome.com/extensions/declarativeContent – Dayton Wang Feb 06 '15 at 22:07
  • @gui47 In theory, that would be the preferred solution. In practice, that method is not yet usable with optional permissions, see https://code.google.com/p/chromium/issues/detail?id=429944. – Rob W Feb 06 '15 at 23:57
  • 1
    I've marked the question as a duplicate because of the overlap of topic. Currently you cannot inject in a specific frame (only all frames), but [there is work in progress](https://code.google.com/p/chromium/issues/detail?id=63979). – Rob W Feb 07 '15 at 00:03
  • For future reference, both issues are now fixed. Good to know that @RobW is a Chromium author – IvanRF Jun 07 '17 at 19:46

0 Answers0