Skip to content

Instantly share code, notes, and snippets.

@sjwaight
Created September 21, 2021 05:30
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 sjwaight/c1b298377661ca6c518ad1ae27362bed to your computer and use it in GitHub Desktop.
Save sjwaight/c1b298377661ca6c518ad1ae27362bed to your computer and use it in GitHub Desktop.
Simple Node / JavaScript code to use Playwright to retrieve details from a website.
CheckMSAU: async function(context) {
var hasConsole = false;
const url = 'https://www.microsoft.com/en-au/d/xbox-series-x/8wj714n3rbtl?activetab=pivot%3aoverviewtab';
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto(url);
try
{
// find the element and retrieve the attribute that tells the browser if it can be clicked
const elementValue = await page.getAttribute("#buttons_ConfigureDeviceButton", "aria-disabled");
if(elementValue != "true")
{
hasConsole = true;
context.log("MSAU: XBox Series X in stock! :)");
}
else
{
context.log("MSAU: XBox X still out of stock. :(");
}
}
catch (e)
{
if(e instanceof TimeoutError)
{
context.log("Took too long to find the element!");
}
}
await browser.close();
return new LookupResponse(consoleAvailable = hasConsole, pageLink = url);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment