diff --git a/atom/renderer/api/atom_api_web_frame.cc b/atom/renderer/api/atom_api_web_frame.cc index 9c83fc8e2f59..dd28ad7a97b3 100644 --- a/atom/renderer/api/atom_api_web_frame.cc +++ b/atom/renderer/api/atom_api_web_frame.cc @@ -146,6 +146,7 @@ void WebFrame::RegisterURLSchemeAsPrivileged(const std::string& scheme) { privileged_scheme); blink::WebSecurityPolicy::registerURLSchemeAsSupportingFetchAPI( privileged_scheme); + blink::WebSecurityPolicy::registerURLSchemeAsCORSEnabled(privileged_scheme); } void WebFrame::InsertText(const std::string& text) { diff --git a/spec/api-web-frame-spec.js b/spec/api-web-frame-spec.js index 450bf1c33ec1..a41bc477018f 100644 --- a/spec/api-web-frame-spec.js +++ b/spec/api-web-frame-spec.js @@ -1,6 +1,8 @@ const assert = require('assert') const path = require('path') -const webFrame = require('electron').webFrame +const {closeWindow} = require('./window-helpers') +const {remote, webFrame} = require('electron') +const {BrowserWindow, protocol, ipcMain} = remote describe('webFrame module', function () { var fixtures = path.resolve(__dirname, 'fixtures') @@ -15,5 +17,48 @@ describe('webFrame module', function () { done('unexpected error : ' + err) }) }) + + it('allows CORS requests', function (done) { + const standardScheme = remote.getGlobal('standardScheme') + const url = standardScheme + '://fake-host' + const content = ` + + ` + var w = new BrowserWindow({show: false}) + after(function (done) { + protocol.unregisterProtocol('cors', function () { + protocol.unregisterProtocol(standardScheme, function () { + closeWindow(w).then(function () { + w = null + done() + }) + }) + }) + }) + + const handler = function (request, callback) { + callback({data: content, mimeType: 'text/html'}) + } + protocol.registerStringProtocol(standardScheme, handler, function (error) { + if (error) return done(error) + }) + + protocol.registerStringProtocol('cors', function (request, callback) { + callback('') + }, function (error) { + if (error) return done(error) + ipcMain.once('response', function (event, status) { + assert.equal(status, 200) + done() + }) + w.loadURL(url) + }) + }) }) })