Skip to content

Instantly share code, notes, and snippets.

@dotproto
Created July 23, 2021 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotproto/83f8354b452472576272966ea4b09c6e to your computer and use it in GitHub Desktop.
Save dotproto/83f8354b452472576272966ea4b09c6e to your computer and use it in GitHub Desktop.
Manifest V3 importScripts try/catch demo
// Copyright 2021 Google LLC
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
// Use importScripts to load other JS files
importScripts('./lib.js');
console.log(self.demo.greeting);
/*
* Uncomment this block and reload the extension to see how errors are
* handled. Currently (as of 2021-07-23) the extension's error page will
* log "SyntaxError: Unexpected end of input", but the console will contain
* a more detailed log message showing what error was thrown and where.
*/
// throw new Error('Testing error handling');
// Copyright 2021 Google LLC
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
try {
importScripts('./background.js');
} catch (e) {
console.error(e);
}
// Copyright 2021 Google LLC
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
self.demo = {
greeting: 'Hello, world!'
}
{
"name": "importScripts try/catch demo",
"version": "1.0",
"manifest_version": 3,
"background": {
"service_worker": "bg-wrapper.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment