Firefox WebExtension Web Application Import Services

I feel stunned by the many different approaches, guidelines, and yet none of them tried to work for me. Please connect at least some of the points for me ...

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

Problem. I cannot import the Services library to use it to search for a window object.

Two methods I've tried:

  • Components.utils.import("resource://gre/modules/Services.jsm"); Provides a warning that Components deprived, and the error: Components.utils is undefined.
  • const { Cu } = require("chrome"); let Services = Cu.import("resource://gre/modules/Services.jsm"); Throws an error message require undefined.

This is a background script, point me in the right direction, how to import the necessary libraries / interfaces that I need to work with?

+5
source share
1 answer

MDN top-level page for add-ons used to get an overview of various types of extensions (since only FF57 web extensions are supported).

Components.utils.import

this is for re-xul (legacy) extensions.

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

This is for SDK extensions.

None of these will work in webextensions.

Unlike other types of extensions, webextensions are restrictive; they do not provide access to the low-level APIs that you can find throughout the wiki.

Therefore, when searching for documentation related to this type of extension, stick to the pages that are under the webextensions hierarchy or the standard web APIs.

+4
source

Source: https://habr.com/ru/post/1246150/


All Articles