diff --git a/lib/node/init.ts b/lib/node/init.ts index 8857eabb6bb0..341666db09e1 100644 --- a/lib/node/init.ts +++ b/lib/node/init.ts @@ -6,7 +6,7 @@ wrapFsWithAsar(require('fs')); // See ElectronRendererClient::DidCreateScriptContext. if ((globalThis as any).blinkfetch) { - const keys = ['fetch', 'Response', 'FormData', 'Request', 'Headers']; + const keys = ['fetch', 'Response', 'FormData', 'Request', 'Headers', 'EventSource']; for (const key of keys) { (globalThis as any)[key] = (globalThis as any)[`blink${key}`]; } diff --git a/lib/worker/init.ts b/lib/worker/init.ts index d23a4f942bb4..ccbd3596fca1 100644 --- a/lib/worker/init.ts +++ b/lib/worker/init.ts @@ -19,7 +19,7 @@ global.require = makeRequireFunction(global.module); // See WebWorkerObserver::WorkerScriptReadyForEvaluation. if ((globalThis as any).blinkfetch) { - const keys = ['fetch', 'Response', 'FormData', 'Request', 'Headers']; + const keys = ['fetch', 'Response', 'FormData', 'Request', 'Headers', 'EventSource']; for (const key of keys) { (globalThis as any)[key] = (globalThis as any)[`blink${key}`]; } diff --git a/shell/renderer/electron_renderer_client.cc b/shell/renderer/electron_renderer_client.cc index 0271cd6206e0..6e69d39c6dda 100644 --- a/shell/renderer/electron_renderer_client.cc +++ b/shell/renderer/electron_renderer_client.cc @@ -118,8 +118,8 @@ void ElectronRendererClient::DidCreateScriptContext( v8::Isolate* isolate = env->isolate(); v8::Local global = renderer_context->Global(); - std::vector keys = {"fetch", "Response", "FormData", "Request", - "Headers"}; + std::vector keys = {"fetch", "Response", "FormData", + "Request", "Headers", "EventSource"}; for (const auto& key : keys) { v8::MaybeLocal value = global->Get(renderer_context, gin::StringToV8(isolate, key)); diff --git a/shell/renderer/web_worker_observer.cc b/shell/renderer/web_worker_observer.cc index 6d71e1b3c1f5..295ec163a2e6 100644 --- a/shell/renderer/web_worker_observer.cc +++ b/shell/renderer/web_worker_observer.cc @@ -71,8 +71,8 @@ void WebWorkerObserver::WorkerScriptReadyForEvaluation( // is loaded. See corresponding change in node/init.ts. v8::Local global = worker_context->Global(); - std::vector keys = {"fetch", "Response", "FormData", "Request", - "Headers"}; + std::vector keys = {"fetch", "Response", "FormData", + "Request", "Headers", "EventSource"}; for (const auto& key : keys) { v8::MaybeLocal value = global->Get(worker_context, gin::StringToV8(isolate, key.c_str())); diff --git a/spec/chromium-spec.ts b/spec/chromium-spec.ts index e74de1aa9ed1..923b6d41b67d 100644 --- a/spec/chromium-spec.ts +++ b/spec/chromium-spec.ts @@ -1028,6 +1028,43 @@ describe('chromium features', () => { expect(code).to.equal(0); }); + itremote('Worker with nodeIntegrationInWorker has access to EventSource', () => { + const es = new EventSource('https://example.com'); + expect(es).to.have.property('url').that.is.a('string'); + expect(es).to.have.property('readyState').that.is.a('number'); + expect(es).to.have.property('withCredentials').that.is.a('boolean'); + }); + + itremote('Worker with nodeIntegrationInWorker has access to fetch-dependent interfaces', async (fixtures: string) => { + const file = require('node:path').join(fixtures, 'hello.txt'); + expect(() => { + fetch('file://' + file); + }).to.not.throw(); + + expect(() => { + const formData = new FormData(); + formData.append('username', 'Groucho'); + }).not.to.throw(); + + expect(() => { + const request = new Request('https://example.com', { + method: 'POST', + body: JSON.stringify({ foo: 'bar' }) + }); + expect(request.method).to.equal('POST'); + }).not.to.throw(); + + expect(() => { + const response = new Response('Hello, world!'); + expect(response.status).to.equal(200); + }).not.to.throw(); + + expect(() => { + const headers = new Headers(); + headers.append('Content-Type', 'text/xml'); + }).not.to.throw(); + }, [path.join(__dirname, 'fixtures')]); + it('Worker can work', async () => { const w = new BrowserWindow({ show: false }); await w.loadURL(`file://${fixturesPath}/pages/blank.html`); diff --git a/spec/node-spec.ts b/spec/node-spec.ts index d3f68030a2ab..0d22f3fbfd71 100644 --- a/spec/node-spec.ts +++ b/spec/node-spec.ts @@ -162,6 +162,15 @@ describe('node feature', () => { }); }); + describe('EventSource', () => { + itremote('works correctly when nodeIntegration is enabled in the renderer', () => { + const es = new EventSource('https://example.com'); + expect(es).to.have.property('url').that.is.a('string'); + expect(es).to.have.property('readyState').that.is.a('number'); + expect(es).to.have.property('withCredentials').that.is.a('boolean'); + }); + }); + describe('fetch', () => { itremote('works correctly when nodeIntegration is enabled in the renderer', async (fixtures: string) => { const file = require('node:path').join(fixtures, 'hello.txt');