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

fix: make protocol wrapper remote-friendly again #27044

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/browser/api/protocol.ts
Expand Up @@ -17,8 +17,12 @@ Object.setPrototypeOf(protocol, new Proxy({}, {

ownKeys () {
if (!app.isReady()) return [];
return Reflect.ownKeys(session.defaultSession!.protocol);
},

return Object.getOwnPropertyNames(Object.getPrototypeOf(session.defaultSession!.protocol));
has: (target, property: string) => {
if (!app.isReady()) return false;
return Reflect.has(session.defaultSession!.protocol, property);
},

getOwnPropertyDescriptor () {
Expand Down
12 changes: 11 additions & 1 deletion spec-main/api-remote-spec.ts
Expand Up @@ -7,7 +7,7 @@ import { ipcMain, BrowserWindow } from 'electron/main';
import { emittedOnce } from './events-helpers';
import { NativeImage } from 'electron/common';
import { serialize, deserialize } from '../lib/common/type-utils';
import { nativeImage } from 'electron';
import { protocol, nativeImage } from 'electron';

const features = process._linkedBinding('electron_common_features');

Expand Down Expand Up @@ -635,6 +635,16 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
const { functionWithToStringProperty } = require('electron').remote.require(path.join(fixtures, 'module', 'to-string-non-function.js'));
expect(functionWithToStringProperty.toString).to.equal('hello');
});

const protocolKeys = Object.getOwnPropertyNames(protocol);
remotely.it(protocolKeys)('remote.protocol returns all keys', (protocolKeys: [string]) => {
const protocol = require('electron').remote.protocol;
const remoteKeys = Object.getOwnPropertyNames(protocol);
expect(remoteKeys).to.deep.equal(protocolKeys);
for (const key of remoteKeys) {
expect(typeof (protocol as any)[key]).to.equal('function');
}
});
});

describe('remote object in renderer', () => {
Expand Down