Skip to content

Instantly share code, notes, and snippets.

@janbaer
Created March 4, 2022 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janbaer/25cb4b9cab104273f7551b4d5787bb7a to your computer and use it in GitHub Desktop.
Save janbaer/25cb4b9cab104273f7551b4d5787bb7a to your computer and use it in GitHub Desktop.
#!/usr/bin/node
const puppeteer = require('puppeteer');
const fs = require('fs');
// Start Chrome with `--remote-debugging-port=9222` and then goto `localhost:9222/json/version` to get the CDP Url
const cdpUrl = 'ws://localhost:9222/devtools/browser/e3ed8a89-ebb3-40f9-a818-fb1738926229';
const newScript = fs.readFileSync('./new_script.sh', 'utf8');
(async () => {
console.log('connect to browser...');
const browser = await puppeteer.connect({
browserWSEndpoint: cdpUrl,
defaultViewport: null, // disable puppeteer resize
product: 'chrome',
});
const pages = await browser.pages();
const page = pages[pages.length - 1];
const [link] = await page.$x("//li[1]/div/div/div/div/a[contains(., 'Edit tasks')]");
link.evaluate(e => e.click());
await page.waitForNavigation();
const [deployDiv] = await page.$x("//div[@id='panel-editor-list']/ul/li[3]/a")
deployDiv.evaluate(e => e.click());
await page.waitForXPath("//textarea[@id='scriptBody_value']");
await page.$eval('#scriptBody_value', (el, newScript) => el.value = newScript, newScript);
await page.$eval('#updateEnvironmentTask_save', (el) => el.click());
page.goBack();
await page.waitForNavigation();
browser.disconnect();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment