Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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