Taiko: Provide an option to bypass csp header

Created on 16 Mar 2021  路  5Comments  路  Source: getgauge/taiko

Expose an api or a config to bypass csp headers for a page.

CDP api reference: https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-setBypassCSP

good first issue feature

Most helpful comment

I stand corrected, I confirm that we have it working as you described. I think you can mark this as closed!

`
const { openBrowser, goto, write, below, textBox, focus, click, client, evaluate, press, closeBrowser } = require('taiko');
(async () => {

try {

    await openBrowser();

    await goto("https://xxx.my.salesforce.com");

    await write("[email protected]");

    await focus(textBox(below("Password")));

    await write("Password");

    await click("Login");

    await client().send('Page.setBypassCSP', {enabled: true});

    await goto("https://xxx.lightning.force.com/lightning/page/home");

    await evaluate(function(){var script= document.createElement('script'); script.type = 'text/javascript'; script.async = true; script.src = 'https://eu-cdn.xxx.com/users/xxxxx/test/xxx_yyy_https.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(script, s); window._scriptConfig = {smartLoad:true}; });

    await click("HelpMe");

    await focus(textBox({title:"Search..."}));

    await write("Burlington");

    await press("Enter");

....
} catch (error) {

    console.error(error);

} finally {

    await closeBrowser();
}

})();`
No CSP errors, and the script loads correctly

All 5 comments

Can this done using await client().send('Page.setBypassCSP', {enabled: true});?

yes, we should be able to do it as await client().Page.setBypassCSP({enabled:true})

Pinging to bring this back into scope

@marktamis as mentioned above this can be achieved by taiko's client api ... do you think having a separate api would add more value ?

I stand corrected, I confirm that we have it working as you described. I think you can mark this as closed!

`
const { openBrowser, goto, write, below, textBox, focus, click, client, evaluate, press, closeBrowser } = require('taiko');
(async () => {

try {

    await openBrowser();

    await goto("https://xxx.my.salesforce.com");

    await write("[email protected]");

    await focus(textBox(below("Password")));

    await write("Password");

    await click("Login");

    await client().send('Page.setBypassCSP', {enabled: true});

    await goto("https://xxx.lightning.force.com/lightning/page/home");

    await evaluate(function(){var script= document.createElement('script'); script.type = 'text/javascript'; script.async = true; script.src = 'https://eu-cdn.xxx.com/users/xxxxx/test/xxx_yyy_https.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(script, s); window._scriptConfig = {smartLoad:true}; });

    await click("HelpMe");

    await focus(textBox({title:"Search..."}));

    await write("Burlington");

    await press("Enter");

....
} catch (error) {

    console.error(error);

} finally {

    await closeBrowser();
}

})();`
No CSP errors, and the script loads correctly

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SrinivasanTarget picture SrinivasanTarget  路  5Comments

chris-kobrzak picture chris-kobrzak  路  9Comments

HaroldPutman picture HaroldPutman  路  4Comments

tkshnwesper picture tkshnwesper  路  8Comments

lchrennew picture lchrennew  路  3Comments