Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox add-on: inject content script to iframe with src as "about:blank"

We are developing an add-in, and would like to have the content script being injected into the top page and all frames. However we found that the content scripts cannot be injected into iframe with src as "about:blank" or "javascript:...".

Any comment/suggestion?

sample page-mod:

require("sdk/page-mod").PageMod({
            include:["*", "file://*"],
            contentScriptFile: [
                "./content/content.js",
            ],
            attachTo: ["existing","top", "frame"],...
like image 512
Easton L. Avatar asked Jan 07 '15 09:01

Easton L.


1 Answers

I want to update an interesting fact that detected by my teammate Wayland:

The funny thing is that it will work if we build the iframe as following:

It's like if we flush by iframe content by calling 'document.write'.

function buildme() {

  var iframe = ...;
  iframe.contentDocument.open();
  iframe.contentDocument.write("<html><body></body></html>");
  iframe.contentDocument.close()

  var child = iframe.contentDocument.craeteElement("..");
  ...
  iframe.contentDocument.body.appendChild(child);
}

< iframe id = "myframe"
onload = "buildme();" / >
like image 148
Easton L. Avatar answered Oct 04 '22 10:10

Easton L.