Created
March 4, 2022 13:52
-
-
Save janbaer/25cb4b9cab104273f7551b4d5787bb7a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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