🚀 New extension service worker tutorial and guides!

284 views
Skip to first unread message

Amy Dev

unread,
May 2, 2023, 4:10:10 PM5/2/23
to Chromium Extensions

Hello fellow developers, 👋


Earlier this year, we published three extension tutorials to help new developers get started on their extension development journey. I hope these have been helpful! :)


I have some exciting news to share about a new tutorial I'm adding to our getting-started collection! It's called "Quick API Reference" and it will help you easily navigate to Chrome API reference pages using the omnibox. We'll also learn some basic concepts about the extension service worker as we go.


But that's not all! The extension team has also published a set of Extension service worker guides that cover more in-depth topics, such as how extension service workers are registered and updated, what the service worker lifecycle looks like in an extension, how imports work, and more.


We're always looking to improve our documentation on extension service workers so that it's easy to understand and addresses all your questions. And that's where you can help! We would really appreciate your feedback on these new articles. You can share your thoughts and suggestions on this post or create an issue on the developer.chrome.com GitHub repository. 


Thank you so much for taking the time to help us make our documentation better!


Keep building awesome Chrome extensions! 🙂


Amy Steam Technical writer for the extensions team 🧩

 


Amy Dev

unread,
May 2, 2023, 5:17:01 PM5/2/23
to Chromium Extensions, Amy Dev
Whoops, I forgot to include the link to the tutorial! Here you go :)

Stefan Van Damme

unread,
May 2, 2023, 5:26:42 PM5/2/23
to Chromium Extensions, Amy Dev
Hi Amy,

Thank you for sharing the exciting news about the new "Quick API Reference" tutorial and the set of Extension service worker guides. It is great to see that the extension team is continuously improving the documentation to help developers in their extension development journey.

I will definitely share my feedback on these new articles and suggest any improvements that I come across. ;-)

Thanks,
Stefan vd


Jackie Han

unread,
May 3, 2023, 3:56:34 AM5/3/23
to Amy Dev, Chromium Extensions
Thanks for sharing new docs!

I would like to point out some issues :)


1. A suggestion

chrome.omnibox.onInputChanged.addListener(async (input, suggest) => {
  ......
  const { apiSuggestions } = await chrome.storage.local.get('apiSuggestions');
  ......
});


onInputChanged event is fired very frequently when users type characters. In practice, this place should:
1) "debounce" user inputs. (here no debounce input)
2) cache data and reuse cache. (here read storage every time when input changes)


2. A mistake: "Alarms are not saved when you close Chrome. So we need to ……"

This is not correct. Chrome does remember alarms (like contextMenus) across browser quit-then-relaunch and extension disable-then-enable. So in this case, you can move "createAlarm()" in runtime.onInstalled callback, instead of at the top level of SW that executes every time when SW startup.



"Extension startup: When a user or incognito profile starts, the chrome.runtime.onStartup event fires but no service worker events are invoked."

chrome.runtime.onStartup event is not fired when an incognito profile is started as the api reference says.


1. ServiceWorkerGlobal.fetch

"Fired when anything is retrieved from the extension package or when fetch() and XMLHttpRequest() are called from a content or popup script."

Above statement makes people mistakenly think it refers to content scripts. `fetch()` from a content script doesn't fire the "fetch" event in extension's SW, because content scripts run in web pages' origin. I suggest updating it to "extension pages or popup page". 
Also, although the "fetch" event is available, it is rarely used in extensions, because all resources are bundled in the extension package.

2. ServiceWorkerGlobal.message

"Extension service workers cannot send messages to popup or content scripts using postMessage()"

postMessage() can send messages from SW to the popup page when it opens. Because the popup page is in the extension's origin.


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/f8bfadd9-2370-43ce-8a4d-3435f7fc3c17n%40chromium.org.
Reply all
Reply to author
Forward
0 new messages