Firefox WebExtension importing Services

穿精又带淫゛_ 提交于 2019-11-26 17:25:57

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/36332561/firefox-webextension-importing-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!