"Browser is not defined" 运行 firefox 示例扩展时出错
"Browser is not defined" error when running firefox sample extension
我在 GNU/Linux 系统中安装了 60.4.0esr(64 位)。当 运行 连接 find-across-tabs 扩展时,我收到错误消息
ReferenceError: browser is not defined[Learn More]
find.js:1:5
<anonymous>
file:///home/username/webextensions-examples-master/find-across-tabs/find.js:1:5
我能够 运行 像 borderify 这样的扩展正确
我认为错误很明显。这里的问题是
ReferenceError: browser is not defined
在:
let backgroundPage = browser.extension.getBackgroundPage();
他们可能在引用 mozilla.org docs。您可以在那里测试示例,看看是否出现错误。
您可以运行直接在popup中使用该功能。例如:
假设一个后台脚本定义了一个函数 foo():
// background.js
function foo() {
console.log("I'm defined in background.js");
}
弹出窗口中的脚本运行ning可以像这样直接调用此函数:
// popup.js
var page = browser.extension.getBackgroundPage();
page.foo(); // -> "I'm defined in background.js"
注意:问题是如果您没有使用隐私浏览模式,因为此功能无法使用它。这是由于 this 错误。它总是 return null
.
我在 GNU/Linux 系统中安装了 60.4.0esr(64 位)。当 运行 连接 find-across-tabs 扩展时,我收到错误消息
ReferenceError: browser is not defined[Learn More]
find.js:1:5
<anonymous>
file:///home/username/webextensions-examples-master/find-across-tabs/find.js:1:5
我能够 运行 像 borderify 这样的扩展正确
我认为错误很明显。这里的问题是
ReferenceError: browser is not defined
在:
let backgroundPage = browser.extension.getBackgroundPage();
他们可能在引用 mozilla.org docs。您可以在那里测试示例,看看是否出现错误。
您可以运行直接在popup中使用该功能。例如:
假设一个后台脚本定义了一个函数 foo():
// background.js
function foo() {
console.log("I'm defined in background.js");
}
弹出窗口中的脚本运行ning可以像这样直接调用此函数:
// popup.js
var page = browser.extension.getBackgroundPage();
page.foo(); // -> "I'm defined in background.js"
注意:问题是如果您没有使用隐私浏览模式,因为此功能无法使用它。这是由于 this 错误。它总是 return null
.