Firefox WebExtension导入服务 [英] Firefox WebExtension importing Services
问题描述
我的目标是在Firefox WebExtension的后台脚本中找到一个窗口对象。 b
问题,我无法导入 Services
库来使用它来查找窗口
对象。
我尝试了两种方法:
-
组件。 utils.import(resource://gre/modules/Services.jsm);
给出一个警告:Components
被depricated,并且一个错误:Components.utils
是未定义的 。 -
const {Cu} = require(chrome);
引发
让Services = Cu.import(resource://gre/modules/Services.jsm);require 是未定义的。
这是一个后台脚本,指向我正确的方向如何导入我需要的正确的库/接口与工作?
MDN顶级页面用于概述不同的扩展类型(因为只支持FF57)。
Components.utils.import
/ b>
$ b
const {Cu} = require(chrome);
/ blockquote>
这是SDK扩展。
两者都不能在webextensions中使用。
与其他扩展类型webextension不同s是限制性的,它们不提供访问你可以在wiki上找到的底层API。
因此,坚持 webextensions hierarchy 或标准网络API当您查找与此扩展相关的文档时键入。
I am feeling overwhelmed by so many different approaches, guides, and yet none I tried work for me. Please connect at least some of the dots for me...
My objective is to find a window object in background script of Firefox WebExtension.
Problem, I cannot import
Services
library to use it for finding awindow
object.Two methods I tried:
Components.utils.import("resource://gre/modules/Services.jsm");
Gives a warning thatComponents
is depricated, and an error:Components.utils
is undefined.const { Cu } = require("chrome"); let Services = Cu.import("resource://gre/modules/Services.jsm");
Throws an error thatrequire
is undefined.That is a background script, point me to the right direction how to import the proper libraries/interfaces I need to work with?
解决方案The MDN top level page for addons used to give an overview over the different extension types (since FF57 only webextensions are supported).
Components.utils.import
this is for restartless/XUL (legacy) extensions.
const { Cu } = require("chrome");
this is for SDK extensions.
Neither will work in webextensions.
Unlike the other extension types webextensions are restrictive, they do not provide access to the low-level APIs that you can find all over the wiki.
So stick to pages that are under the webextensions hierarchy or standard web APIs when you're looking for documentation related to this extension type.
这篇关于Firefox WebExtension导入服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!