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.

Posted on 2023-09-01