RESOLVED INVALID 268143
Web Inspector: Log message from service worker is not going through on 127.0.0.1 or localhost
https://bugs.webkit.org/show_bug.cgi?id=268143
Summary Web Inspector: Log message from service worker is not going through on 127.0....
Karl Dubost
Reported 2024-01-25 22:08:10 PST
Create a file index.html ===================================================== <!DOCTYPE html> <html> <title>Demo</title> <script src="script.js"></script> <body> </body> </html> ===================================================== Create a script.js ===================================================== const check = () => { if (!("serviceWorker" in navigator)) { throw new Error("No Service Worker support!"); } }; const registerServiceWorker = async () => { const swRegistration = await navigator.serviceWorker.register("service.js"); return swRegistration; }; const main = async () => { check(); const swRegistration = await registerServiceWorker(); }; main(); ===================================================== And in service.js ===================================================== console.log('Hello from service.js in the console'); ===================================================== 1. go to the directory where the files are 2. start python3 -m http.server 3. Go to http://localhost:8000 or http://127.0.0.1:8000 Safari: nothing in the console Firefox: nothing in the console Chrome: Hello from service.js in the console
Attachments
Screenshot of web inspector (321.59 KB, image/png)
2024-01-29 18:29 PST, Karl Dubost
no flags
Radar WebKit Bug Importer
Comment 1 2024-01-25 22:08:35 PST
Karl Dubost
Comment 2 2024-01-29 18:29:07 PST
Created attachment 469613 [details] Screenshot of web inspector Ah in fact it goes through. Just not in the same window. Thanks to Razvan for pointing out. To make the service work log visible, it is necessary to: 1. Go to Develop Menu 2. Go to Service Workers 3. Select the service workers for the right URL (see screenshot) Maybe I should rename this bug as Notify the main console about log messages in Service Workers console?
Razvan Caliman
Comment 3 2024-01-31 06:40:14 PST
Closing this bug as not applicable. Service workers are an independent inspection target, separate from the inspected page. `console.log` messages from the service worker don't show up in the inspector for the inspected page. To inspect a service worker on macOS, follow the instructions here: https://developer.apple.com/documentation/safari-developer-tools/inspecting-safari-macos#Inspecting-a-service-worker (In reply to Karl Dubost from comment #2) > Maybe I should rename this bug as > Notify the main console about log messages in Service Workers console? A few counter-arguments for relaying messages from the service worker context to the inspected page context: - links in messages to source files would have to open in Sources tab. There, developers will expect to set breakpoints, use local overrides, and use other features of the Sources tab. For this to work, the debugger needs to interact with the service worker context, not the inspected page. There is significant work involved in getting this to work. - stateful objects from the service worker context would also need to be relayed to the inspector for the inspected page (ex: progressive disclosure of objects in console messages, contents of cache storage, etc.) - showing messages from the service worker in the console for the inspected page creates the expectation that a developer can issue commands and interact with the service worker context from this console: accessing state, issuing commands, etc. For this to work, the console would need to switch context to the service worker. Having just one-way message relaying from the service worker, but not bi-directional communication, will lead to further confusion. For these reasons, I believe it's best to stick to the workflow of having a dedic Web Inspector instance for the service worker explained in the documentation linked above.
Note You need to log in before you can comment on or make changes to this bug.