fix: make sure service worker scheme is registered with allowServiceWorkers (#28326)
* Fix custom scheme not registered as service worker scheme * ServiceWorker loaders do not have WebContents associated * Add test for service worker * Revert "Fix custom scheme not registered as service worker scheme" This reverts commit a249235b220a0edcfcb906e0b3b3c0486ece73a6. * Add scheme to ServiceWorkerSchemes
This commit is contained in:
parent
7c36463085
commit
1e9e2f8cf6
4 changed files with 54 additions and 9 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import { v4 } from 'uuid';
|
||||
import { protocol, webContents, WebContents, session, BrowserWindow, ipcMain } from 'electron/main';
|
||||
import { AddressInfo } from 'net';
|
||||
import * as ChildProcess from 'child_process';
|
||||
|
|
@ -724,6 +725,36 @@ describe('protocol module', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('protocol.registerSchemesAsPrivileged allowServiceWorkers', () => {
|
||||
const { serviceWorkerScheme } = global as any;
|
||||
protocol.registerStringProtocol(serviceWorkerScheme, (request, cb) => {
|
||||
if (request.url.endsWith('.js')) {
|
||||
cb({
|
||||
mimeType: 'text/javascript',
|
||||
charset: 'utf-8',
|
||||
data: 'console.log("Loaded")'
|
||||
});
|
||||
} else {
|
||||
cb({
|
||||
mimeType: 'text/html',
|
||||
charset: 'utf-8',
|
||||
data: '<!DOCTYPE html>'
|
||||
});
|
||||
}
|
||||
});
|
||||
after(() => protocol.unregisterProtocol(serviceWorkerScheme));
|
||||
|
||||
it('should fail when registering invalid service worker', async () => {
|
||||
await contents.loadURL(`${serviceWorkerScheme}://${v4()}.com`);
|
||||
await expect(contents.executeJavaScript(`navigator.serviceWorker.register('${v4()}.notjs', {scope: './'})`)).to.be.rejected();
|
||||
});
|
||||
|
||||
it('should be able to register service worker for custom scheme', async () => {
|
||||
await contents.loadURL(`${serviceWorkerScheme}://${v4()}.com`);
|
||||
await contents.executeJavaScript(`navigator.serviceWorker.register('${v4()}.js', {scope: './'})`);
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('protocol.registerSchemesAsPrivileged standard', () => {
|
||||
const standardScheme = (global as any).standardScheme;
|
||||
const origin = `${standardScheme}://fake-host`;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue