Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vitest-webextension-mock

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vitest-webextension-mock

Mock webextension APIs with vitest functions

  • 0.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

vitest-webextension-mock

npm version Code coverage

Questions

What should we do with the differences between the specs and the chrome implementation?
For an example, according to the spec, browser.action.setTitle should take

setTitle({title: string, windowId: number, tabId: number})

according to the specs (MDN), but the chrome implementation is (docs):

setTitle({title: string, tabId: number}, callback: Function)

What should we do in such cases?

  • Offer a way for consumers to configure which flavour of the API they want to use?
  • Only do chrome flavour? Only do official spec flavour?

We should for sure look at webextension-polyfill which solves this problem and follow what they do (which is most likely following the spec)

TODO

  • Make extension URL configurable so consumers can control the path returned by browser.runtime.getURL()
    • Make browser configurable so it changes the scheme chrome-extension:// or moz-extension://
    • Allow user to provide extension ID

Docs

The mock functions will try to emulate browser behavior as best they can. For an example:

browser.action.getTitle({windowId: 1, tabId: 1}) 

Will return an error because according to the specs, if both windowId and tabId are supplied, getTitle should return an error.

However, we rely on typescript for parameters null checks:

browser.action.getTitle()

is an invalid call as getTitle expects 1 parameter. The mocked function will not throw if called without a parameter. We recommend you use typescript with @types/webextension-polyfill to catch these errors at build time.

Keywords

FAQs

Package last updated on 02 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc