+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/api/service-worker-main.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ An [`IpcMainServiceWorker`](ipc-main-service-worker.md) instance scoped to the s

A `string` representing the scope URL of the service worker.

#### `serviceWorker.scriptURL` _Readonly_ _Experimental_

A `string` representing the script URL of the service worker.

#### `serviceWorker.versionId` _Readonly_ _Experimental_

A `number` representing the ID of the specific version of the service worker script in its scope.
Expand Down
7 changes: 7 additions & 0 deletions shell/browser/api/electron_api_service_worker_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ GURL ServiceWorkerMain::ScopeURL() const {
return version_info()->scope;
}

GURL ServiceWorkerMain::ScriptURL() const {
if (version_destroyed_)
return {};
return version_info()->script_url;
}

// static
gin::Handle<ServiceWorkerMain> ServiceWorkerMain::New(v8::Isolate* isolate) {
return gin::Handle<ServiceWorkerMain>();
Expand Down Expand Up @@ -331,6 +337,7 @@ void ServiceWorkerMain::FillObjectTemplate(
&ServiceWorkerMain::CountExternalRequestsForTest)
.SetProperty("versionId", &ServiceWorkerMain::VersionID)
.SetProperty("scope", &ServiceWorkerMain::ScopeURL)
.SetProperty("scriptURL", &ServiceWorkerMain::ScriptURL)
.Build();
}

Expand Down
1 change: 1 addition & 0 deletions shell/browser/api/electron_api_service_worker_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class ServiceWorkerMain final

int64_t VersionID() const;
GURL ScopeURL() const;
GURL ScriptURL() const;

// Version ID unique only to the StoragePartition.
int64_t version_id_;
Expand Down
11 changes: 11 additions & 0 deletions spec/api-service-worker-main-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,17 @@ describe('ServiceWorkerMain module', () => {
});
});

describe("'scriptURL' property", () => {
it('matches the expected value', async () => {
loadWorkerScript();
const serviceWorker = await waitForServiceWorker();
expect(serviceWorker).to.not.be.undefined();
if (!serviceWorker) return;
expect(serviceWorker).to.have.property('scriptURL').that.is.a('string');
expect(serviceWorker.scriptURL).to.equal(`${baseUrl}/sw.js`);
});
});

describe('ipc', () => {
beforeEach(() => {
registerPreload('preload-tests.js');
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载