Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add API for receiving logs from service workers #20624

Merged
merged 10 commits into from Feb 20, 2020

Conversation

MarshallOfSound
Copy link
Member

@MarshallOfSound MarshallOfSound commented Oct 17, 2019

Pretty simple API here, plans are for the following

  • console-message event. Vaguely equivalent to the console-message event on the webContents API so that apps can capture logs from their service workers.
  • getWorkerInfoFromID() Get service worker scope and script url for a given ID
  • getRunningWorkerInfos() Get service worker scope, script url and id for all active workers

The second two APIs are blocked on a Chromium roll hence WIP, the event is already implemented.

TODO:

  • console-message
  • getAll()
  • getFromVersionId()
  • Docs
  • Tests

Notes: Added session.serviceWorkerContext API to access basic service worker info and receive console logs from service workers.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Oct 17, 2019
@miniak
Copy link
Contributor

miniak commented Oct 18, 2019

@MarshallOfSound Is session.getRunningWorkerInfos() a replacement for webContents.getAllSharedWorkers() added in #20389?

@miniak
Copy link
Contributor

miniak commented Oct 18, 2019

@MarshallOfSound should we also deprecate webContents.inspectServiceWorker() and webContents.inspectSharedWorker() and replace it with a new API that supports any type of worker?

@MarshallOfSound
Copy link
Member Author

@miniak SharedWorker !== ServiceWorker afaik. This APIs primary purpose is getting logs from service workers. If we feel it's appropriate for this to work for all workers that is substantially more complicated as service workers, shared workers and web workers are each very different things in Chrome

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Oct 18, 2019
@MarshallOfSound MarshallOfSound changed the title [WIP] feat: add API for receiving logs from service workers feat: add API for receiving logs from service workers Nov 20, 2019
@MarshallOfSound
Copy link
Member Author

Removing WIP as this is ready for code review. I'll work on tests shortly 👍


namespace {

std::string MessageSourceToString(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gin converter?

shell/browser/api/atom_api_service_worker_context.cc Outdated Show resolved Hide resolved
shell/browser/api/atom_api_service_worker_context.cc Outdated Show resolved Hide resolved
shell/browser/api/atom_api_service_worker_context.cc Outdated Show resolved Hide resolved
shell/browser/api/atom_api_service_worker_context.cc Outdated Show resolved Hide resolved
shell/browser/api/atom_api_service_worker_context.cc Outdated Show resolved Hide resolved
Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, please add tests.

@MarshallOfSound MarshallOfSound force-pushed the service-worker-logging-api branch 2 times, most recently from fc0a70d to 4a0ec9c Compare January 9, 2020 23:07
docs/api/service-workers.md Show resolved Hide resolved
docs/api/service-workers.md Show resolved Hide resolved

* `scriptUrl` String - The full URL to the script that this service worker runs
* `scope` String - The base URL that this service worker is active for.
* `renderProcessId` Number - The virtual ID of the process that this service worker is running in. This is not an OS level PID. This aligns with the ID set used for `webContents.getProcessId()`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we wanted to add e.g. methods for killing / restarting service workers, would they go on this object? e.g.

session.defaultSession.serviceWorkers.getAllRunning().forEach(sw => sw.shutdown())

or something else?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either that, or have serviceWorkers.stopByVersionId(versionid)

spec-main/api-service-workers-spec.ts Show resolved Hide resolved
spec-main/api-service-workers-spec.ts Outdated Show resolved Hide resolved
@release-clerk
Copy link

release-clerk bot commented Feb 20, 2020

Release Notes Persisted

Added session.serviceWorkerContext API to access basic service worker info and receive console logs from service workers.

@MarshallOfSound MarshallOfSound deleted the service-worker-logging-api branch February 20, 2020 23:19
@trop
Copy link
Contributor

trop bot commented Feb 20, 2020

I have automatically backported this PR to "9-x-y", please check out #22313

@sofianguy sofianguy added this to Fixed in 9.0.0-beta.4 in 9-x-y Mar 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
9-x-y
Fixed in 9.0.0-beta.4
Development

Successfully merging this pull request may close these issues.

None yet

3 participants