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

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

问题描述

我对这么多不同的方法、指南感到不知所措,但我没有尝试为我工作.请至少为我连接一些点...

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...

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

My objective is to find a window object in background script of Firefox WebExtension.

问题,我无法导入Services 库来使用它来查找window 对象.

Problem, I cannot import Services library to use it for finding a window object.

我尝试过的两种方法:

  1. Components.utils.import("resource://gre/modules/Services.jsm"); 警告 Components 已弃用,并出现错误:Components.utils 未定义.
  2. const { Cu } = require("chrome");let Services = Cu.import("resource://gre/modules/Services.jsm"); 抛出一个 require 未定义的错误.
  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?

推荐答案

用于插件的 MDN 顶级页面 用于概述不同的扩展类型(因为 FF57 只支持 webextensions).

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

Components.utils.import

这是用于无重启/XUL(传统)扩展.

this is for restartless/XUL (legacy) extensions.

const { Cu } = require("chrome");

const { Cu } = require("chrome");

这是用于 SDK 扩展.

this is for SDK extensions.

在 webextensions 中都不起作用.

Neither will work in webextensions.

与其他扩展类型不同,webextensions 具有限制性,它们不提供对您可以在整个 wiki 中找到的低级 API 的访问.

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.

因此请坚持使用 webextensions 层次结构 下的页面或当您查找与此扩展类型相关的文档时,请使用标准 Web API.

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天全站免登陆