Search code examples
google-chrome-extensionchrome-extension-manifest-v3

chrome.offscreen reason "WORKERS" does not work


chrome.offscreen.createDocument({
  url: chrome.runtime.getURL('off_screen.html'),
  reasons: ['WORKERS'],
  justification: 'reason for needing the document',
});

When I try to create offscreen document for my chrome extension, it throws an error.

Uncaught TypeError: Error in invocation of 
offscreen.createDocument(offscreen.CreateParameters parameters, function callback): 
Error at parameter 'parameters': 
Error at property 'reasons': 
Error at index 1: Value must be one of 
AUDIO_PLAYBACK, BLOBS, CLIPBOARD, DISPLAY_MEDIA, DOM_PARSER, DOM_SCRAPING, 
IFRAME_SCRIPTING, TESTING, USER_MEDIA, WEB_RTC.

In documentation "WORKERS" are clearly there

https://developer.chrome.com/docs/extensions/reference/offscreen/#type-Reason

Why am I getting this error and how can I fix it if possible?


Solution

  • See what's new: WORKERS was added in Chrome 113.

    In older versions of Chrome you can use a fallback reason like this:

      reasons: [chrome.offscreen.Reason.WORKERS || chrome.offscreen.Reason.IFRAME_SCRIPTING],