xiaoxiaoflood / firefox-scripts

userChromeJS / autoconfig.js and extensions
Mozilla Public License 2.0
1.03k stars 87 forks source link

Access the window object #50

Closed sdavidg closed 4 years ago

sdavidg commented 4 years ago

I want to develop a button that creates a new page and inserts code into it. From javascript it is something simple:

    var win = window.open('','','');
    var doc = win.document;
    doc.open();
    doc.write("hello world!");
    doc.close();
    doc.title = 'speedDial';

but if I use CustomizableUI.createWidget, I don't know how to access the new window element:

    var tab = gBrowser.addTab("about:blank", {triggeringPrincipal: Services.scriptSecurityManager.createNullPrincipal({})});
    tab.linkedBrowser.contentWindow // this is null

Do you know how to access it?

Thank you

xiaoxiaoflood commented 4 years ago

You need to use messages to communicate with content process.

browser.messageManager.loadFrameScript https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Multiprocess_Firefox/Message_Manager

But plase, note this is not a support forum about legacy extension development, so closing as unrelated.