Skip to content

Commit

Permalink
reduce pupeteer security
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Aug 24, 2020
1 parent 94a8d6d commit 7ad9495
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 31 deletions.
5 changes: 4 additions & 1 deletion src/commands/shane/analytics/community/enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export default class CommunityEnable extends SfdxCommand {
public async run(): Promise<any> {
// this.ux.startSpinner('starting headless browser');

const browser = await puppeteer.launch({ headless: !this.flags.showbrowser, args: ['--no-sandbox'] });
const browser = await puppeteer.launch({
headless: !this.flags.showbrowser,
args: ['--no-sandbox', '--disable-web-security', '--disable-features=IsolateOrigins,site-per-process']
});
const context = browser.defaultBrowserContext();

// // get the force-org-open url for your scratch org
Expand Down
52 changes: 25 additions & 27 deletions src/commands/shane/communities/activate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable no-restricted-syntax */
import { flags, SfdxCommand } from '@salesforce/command';
import * as puppeteer from 'puppeteer';

Expand All @@ -16,7 +18,10 @@ export default class CommunityActivate extends SfdxCommand {
public async run(): Promise<any> {
this.ux.startSpinner('starting headless browser');

const browser = await puppeteer.launch({ headless: !this.flags.showbrowser, args: ['--no-sandbox'] });
const browser = await puppeteer.launch({
headless: !this.flags.showbrowser,
args: ['--no-sandbox', '--disable-web-security', '--disable-features=IsolateOrigins,site-per-process']
});
// const context = browser.defaultBrowserContext();

// // get the force-org-open url for your scratch org
Expand All @@ -27,69 +32,62 @@ export default class CommunityActivate extends SfdxCommand {
const workspacesLink = `a[title*="Workspaces"][title*="${this.flags.name}"]`;
// await context.overridePermissions(url, ['notifications']);
const page = await browser.newPage();

this.ux.setSpinnerStatus(`opening ${url}`);
await page.goto(url, {
waitUntil: 'networkidle2'
});

this.ux.setSpinnerStatus(`waiting for selector iframe[title="${iframeTitle}"]`);
await page.waitForSelector(`iframe[title="${iframeTitle}"]`);
// <a href="/servlet/networks/switch?networkId=0DBZ00000004eq5&amp;startURL=%2FcommunitySetup%2FcwApp.app%23%2Fc%2Fhome&amp;" class="networkManageLink zen-mhs actionLink" data-networkid="0DBZ00000004eq5" data-networkurl="/servlet/networks/switch?networkId=0DBZ00000004eq5&amp;startURL=%2FcommunitySetup%2FcwApp.app%23%2Fc%2Fhome" target="_blank" title="Workspaces - Record 2 - dealers">Workspaces</a>
this.ux.stopSpinner('communities list loaded');
// this.ux.log(page.frames().toString());
this.ux.startSpinner(`iterating ${page.frames().length} frames on the page to find the workspace`);
for (const frame of page.frames()) {
const title = await frame.title();
// this.ux.log(`in frame ${title}`);
if (title === iframeTitle) {
this.ux.setSpinnerStatus(`in matching frame, waiting for ${workspacesLink}`);

await frame.waitForSelector(workspacesLink);

const [newtab] = await Promise.all([
new Promise<puppeteer.Page>(resolve => page.once('popup', resolve)),
frame.click(workspacesLink)
]);
this.ux.setSpinnerStatus(`opened popup, waiting for administration page`);

await newtab.waitForSelector('a.js-workspace-administration');
await newtab.click('a.js-workspace-administration');

this.ux.setSpinnerStatus('administration page loaded. Waiting for iFrames');
// it's in another stupid iframe!!
const activateIframeTitle = `Settings ~ ${this.flags.name}`;
const activateIframeTitleSelector = `iframe[title="${activateIframeTitle}"]`;

newtab.on('dialog', async dialog => {
this.ux.setSpinnerStatus('confirming activation');
await newtab.waitFor(1500);
await dialog.accept();
await newtab.waitFor(1500);
await browser.close();
this.ux.stopSpinner('Activated community');
if (!this.flags.showbrowser) {
await browser.close();
this.ux.stopSpinner('Activated community');
}
return true;
});

await newtab.waitForSelector(activateIframeTitleSelector);
this.ux.setSpinnerStatus('finding matching iframe for activation');

for (const innerFrame of newtab.frames()) {
const innerTitle = await innerFrame.title();
if (innerTitle === activateIframeTitle) {
this.ux.setSpinnerStatus('activation button found. Clicking it');

await innerFrame.waitForSelector('input[value="Activate Community"]');
await innerFrame.click('input[value="Activate Community"]');
}
}

// <a class="js-workspace-administration slds-text-link--reset slds-m-bottom--small slds-text-align--center slds-box--border js-workspace-tile communitySetupCmcWorkspaceTile" href="javascript:void(0);" data-aura-rendered-by="58:119;a" data-aura-class="communitySetupCmcWorkspaceTile"><div class="slds-m-top--large" data-aura-rendered-by="59:119;a"><lightning-icon class="slds-shrink-none administration slds-icon-standard-custom slds-icon_container" data-data-rendering-service-uid="131" data-aura-rendered-by="61:119;a"><lightning-primitive-icon lightning-primitiveicon_primitiveicon-host=""><svg lightning-primitiveIcon_primitiveIcon="" focusable="false" data-key="custom" aria-hidden="true" class="slds-icon slds-icon_large"><use lightning-primitiveIcon_primitiveIcon="" xlink:href="/externalid/_slds/icons/standard-sprite/svg/symbols.svg?cache=9.24.0#custom"></use></svg></lightning-primitive-icon></lightning-icon></div><div class="slds-text-heading--small slds-m-top--small js-tile-label" data-aura-rendered-by="62:119;a"><strong data-aura-rendered-by="63:119;a">Administration</strong></div><div class="slds-text-body--regular slds-text-color--weak slds-m-top--small slds-m-horizontal--small js-tile-description" data-aura-rendered-by="65:119;a">Configure settings and properties for your community.</div></a>
// // verify that it actually changed value from the click?
// await frame.waitForSelector('input.enableWaveInCommunities:checked');

// await frame.waitForSelector('input[title="Save"]');
// await frame.click('input[title="Save"]');
// // this.ux.log('clicked save');
// await frame.waitFor(500);
// await browser.close();
// return true;
}
}

// const activateButtonSelector = 'button[data-nextstatus="Live"]';

// await page.waitForSelector(activateButtonSelector);
// const activateButton = await page.$(activateButtonSelector);
// await activateButton.click();

// await browser.close();
// this.ux.stopSpinner(`Published community: ${this.flags.name}`);
// return true;
}
}
2 changes: 1 addition & 1 deletion src/commands/shane/connectedapp/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class ConnectedAppAttributes extends SfdxCommand {

const browser = await puppeteer.launch({
headless: !this.flags.showbrowser,
args: ['--no-sandbox', '--disable-features=site-per-process']
args: ['--no-sandbox', '--disable-web-security', '--disable-features=IsolateOrigins,site-per-process']
});
const context = browser.defaultBrowserContext();

Expand Down
5 changes: 4 additions & 1 deletion src/commands/shane/heroku/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ export default class HerokuConnect extends SfdxCommand {

this.ux.setSpinnerStatus('authorizing heroku via browser');

const browser = await puppeteer.launch({ headless: !this.flags.showbrowser, args: ['--no-sandbox'] });
const browser = await puppeteer.launch({
headless: !this.flags.showbrowser,
args: ['--no-sandbox', '--disable-web-security', '--disable-features=IsolateOrigins,site-per-process']
});
const page = await browser.newPage();
await page.goto(sfdcAuthUrl, {
waitUntil: 'networkidle2'
Expand Down
5 changes: 4 additions & 1 deletion src/commands/shane/heroku/externalobjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ export default class HerokuExternalObjects extends SfdxCommand {

this.ux.setSpinnerStatus('logging into heroku');

const browser = await puppeteer.launch({ headless: !this.flags.showbrowser, args: ['--no-sandbox'] });
const browser = await puppeteer.launch({
headless: !this.flags.showbrowser,
args: ['--no-sandbox', '--disable-web-security', '--disable-features=IsolateOrigins,site-per-process']
});
const page = await browser.newPage();
await page.goto(`https://connect.heroku.com/sync/${matchingApp.id}/external`, {
waitUntil: 'networkidle2'
Expand Down

0 comments on commit 7ad9495

Please sign in to comment.