问题标签 [firefox-addon-webextensions]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
517 浏览

firefox-addon - Firefox WebExtention 无法加载

因此,我尝试使用about:debuggingFirefox 中的页面加载我的插件。但是,它根本不会加载。是否有某个地方会记录我可以找到的错误?

这是我的manifest.JSON代码:

我希望这可以帮助其他沮丧的附加组件创建者。

提前致谢

0 投票
2 回答
2157 浏览

javascript - 未选中的 lastError 值:错误:没有匹配的窗口 - 尝试在 Firefox WebExtension 中使用命令执行脚本时出现此错误

我有这部分代码(一切都在 background.js 中),它基本上根据页面的 URL 在页面中执行 javascript。它应该适用于工具栏按钮单击和 Ctrl + Q 命令。

我将它分配给这样的按钮单击,它可以工作:

问题是当我尝试将相同的代码分配给 onCommand 事件时,如下所示:

命令被识别,也是当前活动选项卡的 url,我用上面代码中的这两个 console.log() 命令检查了它,但是当我尝试用命令执行它时,脚本不会被执行。在浏览器控制台中,只有这个错误:

源自://gre/modules/ExtensionUtils.jsm

可能是什么问题,我知道我的 manifest.json 文件没问题,因为命令被识别,但它根本不会执行 javascript ...

0 投票
0 回答
40 浏览

javascript - 从后台页面获取存储并将其返回到内容脚本

我正在尝试向我的扩展程序的后台页面发送一条消息,以从中获取数据chrome.storage并将其返回到请求该数据的内容脚本。chrome.storage由于 Firefox 的兼容性问题,我必须通过后台页面访问。

问题是我使用了 2 个异步函数chrome.storagechrome.runtime.sendMessage,这意味着它undefined总是被返回。

内容脚本:

背景:

0 投票
1 回答
850 浏览

firefox - WebExtension:重新加载选项卡时做出反应

我正在开发一个 Firefox WebExtension,它有一个弹出窗口并用于chrome.storage.local存储状态。到目前为止,我已经使用选项卡 ID 存储特定选项卡的数据。

如果重新加载当前选项卡,我想重新初始化本地存储。这是因为扩展可能对 DOM 进行了一些更改,如果重新加载选项卡,这些更改将会丢失;因此它存储的状态是不正确的。

从弹出窗口调用初始 JavaScript 代码。

重新加载页面时如何运行一些代码?

谢谢

0 投票
2 回答
2620 浏览

javascript - Firefox WebExtensions WebRequest 示例不起作用

我试图遵循此处给出的 webRequest 示例。这个简单的扩展应该将所有请求记录到控制台,但它没有这样做。在我的实际代码中,我包含了一行将页面的边框颜色更改为红色并且确实有效,因此我知道扩展代码正在运行。

要加载我要去的扩展about:debugging并通过Load Temporary Add-on按钮加载它

这是我的实际代码

清单.json

如您所见,我已经从 mozilla 页面上给出的示例中更改了清单,因为复制和粘贴该 json 而不进行任何更改会导致 firefox 甚至不加载扩展

拦截.js

在此处输入图像描述

0 投票
1 回答
101 浏览

javascript - 附加到 webRequest 事件时,有没有办法访问匹配的 URL 模式?

目前正在构建一个网络扩展程序,并且想知道在webRequest.onBeforeRequest将事件与URLFilter对象一起使用时触发事件时在我的背景脚本中匹配了哪个 URL 匹配模式。

不幸的是,回调只接收details包含匹配网站 URL 的对象,而不是匹配模式本身。出于测试目的,mdn 上还描述了一种访问模块的方法,但是有没有一种方法可以访问实际匹配的模式,还是我需要编写自己的正则表达式匹配函数?

0 投票
2 回答
368 浏览

javascript - 如何在 JS/chrome API 中为任何 DOM 对象创建 onClick 侦听器

我想使用 chrome API (JavaScript) 创建简单的 DOM 检查器(您知道 Firefox 开发人员工具中的 DOM 检查器,您可以在其中单击 DOM 元素,它将显示有关该元素的一些信息)。我不是直接使用 Chrome 浏览器,而是使用 Firefox 使用的 chrome API。我知道如何使用 addEventListener 将事件与元素绑定,如下所示:

但是上面代码中的目标是某个指定的元素。我的问题是当我不知道将点击哪个元素时如何实现这个想法。我的意思是,我应该将侦听器绑定到所有 DOM 元素吗?希望有一些更好、更容易和通用的解决方案。我添加了 google-chrome API 标签,因为我认为 Firefox webextensions 中的实现应该与 Chrome 中的类似。

0 投票
1 回答
273 浏览

javascript - Webextension 登录到某个页面并一键继续子页面

我正在处理弹出窗口、内容脚本和背景脚本的组合。不幸的是,我在其中选择的任何沟通方式都未能达到我想要的结果。

我需要在浏览器菜单中使用图标/弹出窗口开发 webextension。单击后,它会在弹出窗口中打开带有项目的专用菜单。当我单击弹出某个项目时.. 选项卡应该打开,它应该转到某个 URL 登录(通过带有参数的 URL 或 POST)并转到子页面(特定于弹出项目文本)。

我正在尝试在弹出窗口和背景脚本之间、背景脚本和内容脚本之间等多种消息组合......但它从来没有对我有用。我也遇到了请求同步的问题,因为虽然我登录(通过 windows.open)我可以执行进一步的子页面加载。

你们知道这怎么可能吗?最好的一些简短的例子?我只使用了标准的 javascript。

我的第一次尝试:

清单.json

popup.html

popup.js

内容.js

0 投票
2 回答
60 浏览

javascript - Why cannot the addon page receive message?

I am trying to send a message from addon (webextension) to a html page which is in the addon. The webextension API is using the chrome interface which is compatible with Chrome browser. I am using Firefox 48 beta.

This is the background script (the "initiate-page" message is important):

So, when the addon receives a message from the module "easy_options", it means that easy_options.html needs some data to load to its document. Therefore I send a message with namespace which contains the data.

Now the addons page easy_options.js (again, the second part is important where chrome.runtime.onMessage listener is added):

What happens is: 1. I send message (A) to background listener and it accepts the message 2. background listener sends message (B) 3. addons options script receives the first message (A) in the runtime.OnMessage listener (I do not want to process this message)

What should happen 1. I send message (A) to background listener and it accepts the message 2. background listener sends message (B) 3. addons options script receives the first message (A) in the runtime.OnMessage listener (I do not want to process this message) 4. addons options script should receive the second message (B) in the runtime.OnMessage listener and I should process it

Question: Why does the fourth step not happen? Why is the message (B alias "initiate-page-response") not received?

Maybe Chrome addon programmers can help too, I think the things should work similarly.

0 投票
1 回答
176 浏览

javascript - 使用 WebExtensions 检测用户桌面不活动

我有一个附加组件,我想在桌面上发出通知,但前提是用户正在积极使用计算机(例如,鼠标指针在任何地方移动,即不仅在浏览器窗口中)。

可以使用 WebExtensions 做到这一点吗?

我相信它会是这样的:

  • 脚本.js

    /li>
  • 背景.js

    /li>