Bypass CORS on Electron render process so that we can crawl websites¶
On chrome browser, ajax can only visit websites with CORS headers. But on Electron APP, we can easily bypass this restriction.
Turn off webSecurity¶
The BrowserWindow
has an webPreferences.webSecurity
option. We can turn off it:
const win = new BrowserWindow({
webPreferences: {
webSecurity: false
}
})
Now we can freely run crawler codes on the render process.
This article is originally created by tooli.top. Please indicate the source when reprinting : https://www.tooli.top/posts/electron_render_bypass_cors
Posted on 2023-09-01
Mail to author