Firefox WebExtension导入服务 [英] Firefox WebExtension importing Services

查看:98
本文介绍了Firefox WebExtension导入服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很多不同的方法,指导,我感到不知所措,但我没有尝试过为我工作。请至少连接一些点...



我的目标是在Firefox WebExtension的后台脚本中找到一个窗口对象。 b

问题,我无法导入 Services 库来使用它来查找窗口对象。

我尝试了两种方法:


  1. 组件。 utils.import(resource://gre/modules/Services.jsm); 给出一个警告: Components 被depricated,并且一个错误: Components.utils 是未定义的

  2. 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 a window object.

Two methods I tried:

  1. Components.utils.import("resource://gre/modules/Services.jsm"); Gives a warning that Components is depricated, and an error: Components.utils is undefined.
  2. const { Cu } = require("chrome"); let Services = Cu.import("resource://gre/modules/Services.jsm"); Throws an error that require 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆