UNPKG

mock-violentmonkey

Version:

Mock violentmonkey's globals for testing userscripts

17 lines 470 B
import { AsyncLocalStorage } from 'node:async_hooks'; const tabIds = new AsyncLocalStorage(); /** * @internal */ const getTabId = () => tabIds.getStore() ?? 0; // Pre-increment means 0 will never be a tab-id // 0 is the tab-id of "no tab" let idSeq = 0; /** * Create a new tab instance * * @returns Returns what the callback returns */ const tabContext = (callback) => tabIds.run(++idSeq, callback); export { getTabId, tabContext }; //# sourceMappingURL=tab.js.map