I am trying to use a local file in Headless Chromium started through Puppeteer.
I always run into the following error:
'Cross origin requests are only supported for protocol schemes: http, data, chrome, https'
I did attempt to set --allow-file-access-from-files
.
It can be reproduced as follows:
const puppeteer = require('puppeteer');
puppeteer.launch({headless:true,args:['--allow-file-access-from-files']}).then(
async browser => {
const page = await browser.newPage();
await page.setContent('<html><head><meta charset="UTF-8"></head><body><div>A page</div></body></html>');
await page.addScriptTag({url:"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"});
await page.on('console', msg => console.log('PAGE LOG:', msg.text()));
await page.evaluate (() => {
$.get('file:///..../cors.js')
.done(
_ => console.log('done')
).fail(
e => console.log('fail:'+JSON.stringify(e))
);
});
await browser.close();
}
);
Looking at the running processes, it does look like Chromium was started with the option.
All tips warmly welcomed!