Skip to content

Instantly share code, notes, and snippets.

@hoelzro
Created August 30, 2024 18:21
Show Gist options
  • Save hoelzro/a95af8e206ce192e83471aaaf2f1ace5 to your computer and use it in GitHub Desktop.
Save hoelzro/a95af8e206ce192e83471aaaf2f1ace5 to your computer and use it in GitHub Desktop.
const { chromium, firefox } = require('playwright');
const child_process = require('child_process');
const process = require('process');
function sleep(ms) {
return new Promise(function(resolve) {
setTimeout(resolve, ms);
});
}
async function main(url) {
if(!url.startsWith('http://') && !url.startsWith('https://')) {
url = `file:///${url}`;
}
url += '#ProblemTiddler';
const browser = await firefox.launch({
headless: false,
});
const page = await browser.newPage();
await page.goto(url);
await page.waitForSelector('.repro-search');
await page.locator('.repro-search').focus();
await sleep(1_000);
let keys = [
'b', 'l', 'a', 'h', 'space',
'b', 'l', 'a', 'h', 'space',
'b', 'l', 'a', 'h'
];
child_process.spawnSync('xdotool', ['key', '--delay', '75'].concat(keys));
await sleep(1_000);
let searchValue = await page.locator('.repro-search').inputValue();
await browser.close();
return searchValue == 'blah blah blah';
}
main(process.argv[2]).then(function(res) {
process.exit(res ? 0 : 1);
}, function(err) {
console.error(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment