如何从Firefox框架脚本postMessage到网页?

时间:2020-12-06 23:19:27

i'm adjusting my extension to Firefox multiprocess (e10s).

我正在调整我对Firefox多进程(e10s)的扩展。

I want to send the webpage some data using a postMessage from the frame-script.

我想使用frame-script中的postMessage向网页发送一些数据。

The Firefox documnatation says i should try to use 'content' object instead of the 'window' object. When trying to access the content page i get an error: .

Firefox文件说我应该尝试使用'content'对象而不是'window'对象。当试图访问内容页面时,我收到一个错误:。

// frame-script.js
addMessageListener("message_from_ext", function(message){
        try{
            var _message = {
                from: "content",
                to: "web",
                data: message
            };
            content.postMessage(_message, "*"); //getting <unavailable> on the content object
        }catch(e){
            console.log(e);
        }
});

how should i access the content object? should i load anything to my frame-script.js?

我该如何访问内容对象?我应该加载任何东西到我的frame-script.js?

(I already succeeded in getting data from the webpage, and sending it to the extension and getting back other data from the extension)

(我已成功从网页获取数据,并将其发送到扩展程序并从扩展程序中获取其他数据)

1 个解决方案

#1


0  

<unavailable> is not an error, it just means the console you have open cannot display the object properly because it lives in another process.

不是错误,它只是意味着您打开的控制台无法正确显示对象,因为它位于另一个进程中。

Open the browser content toolbox and use its console instead to view messages in the content process.

打开浏览器内容工具箱并使用其控制台来查看内容过程中的消息。

#1


0  

<unavailable> is not an error, it just means the console you have open cannot display the object properly because it lives in another process.

不是错误,它只是意味着您打开的控制台无法正确显示对象,因为它位于另一个进程中。

Open the browser content toolbox and use its console instead to view messages in the content process.

打开浏览器内容工具箱并使用其控制台来查看内容过程中的消息。