Final updates for automated checkout behavior

main
Ibraheem Saleh 10 months ago
parent 7ec700a60f
commit cc02ef4363

4
.gitignore vendored

@ -1,2 +1,4 @@
node_modules node_modules
user_data
cookies.json
localStorage.json

@ -1,6 +1,10 @@
# 5090 Bot from wbuffetsukdik reddit user # 5090 Bot from wbuffetsukdik reddit user
Here's the github repository. It requires a bit of technical knowledge to set up, but not too hard. Here's the github repository. It requires a bit of technical knowledge to set up, but not too hard.
## To use
1. `node login` -- login to Best Buy within 1 minute before browser closes on its own!
2. node .
## Install nodeJS and NPM. ## Install nodeJS and NPM.
1. Move the files in the repository into a folder on your computer named "GPUMonitor". 1. Move the files in the repository into a folder on your computer named "GPUMonitor".
1. Open the command line, navigate to the folder using "cd" to move to the file path 1. Open the command line, navigate to the folder using "cd" to move to the file path

@ -2,8 +2,22 @@ import fetch from 'node-fetch';
import { playAudioFile } from 'audic'; import { playAudioFile } from 'audic';
import open from 'open'; import open from 'open';
import puppeteer from 'puppeteer-extra';
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
import AnonymizeUAPlugin from 'puppeteer-extra-plugin-anonymize-ua';
import AdblockerPlugin from 'puppeteer-extra-plugin-adblocker';
import fs from 'fs';
const url = 'https://www.bestbuy.com/gateway/graphql'; const url = 'https://www.bestbuy.com/gateway/graphql';
const browser_path = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe';
puppeteer.use(StealthPlugin());
puppeteer.use(AnonymizeUAPlugin());
puppeteer.use(
AdblockerPlugin({
blockTrackers: true,
}
));
const headers = { const headers = {
'Host': 'www.bestbuy.com', 'Host': 'www.bestbuy.com',
@ -25,7 +39,7 @@ const headers = {
'TE': 'trailers' 'TE': 'trailers'
}; };
const skuIds = ["6614151","6578810","6616096","6617487","6614119","6614120","6616095","6616092","6616096","6614122","6616093","6616090","6616091","6615930","6615929","6615931"] const skuIds = ["6614151","6616096","6617487","6614119","6614120","6616095","6616092","6616096","6614122","6616093","6616090","6616091","6615930","6615929","6615931"]
const queries = skuIds.map(skuId => ({ const queries = skuIds.map(skuId => ({
skuId, skuId,
@ -64,6 +78,54 @@ function getProductUrl(skuId) {
return `https://www.bestbuy.com/site/${skuId}.p?skuId=${skuId}`; return `https://www.bestbuy.com/site/${skuId}.p?skuId=${skuId}`;
} }
async function addToCart(productUrl) {
const browser = await puppeteer.launch({
headless: false,
defaultViewport: null,
ignoreDefaultArgs: ["--disable-extensions"],
dumpio: true,
args: ["--start-maximized", "--no-sandbox", "--disable-setuid-sandbox"],
executablePath: browser_path,
});
const page = await browser.newPage();
// Load cookies
try{
const cookies = JSON.parse(fs.readFileSync('./cookies.json', 'utf8'));
await page.setCookie(...cookies);
}catch (error){
console.error('An error occurred:',error)
}
// Load local storage data
try{
const localStorageData = JSON.parse(fs.readFileSync('./localStorage.json', 'utf8'));
await page.evaluateOnNewDocument((data) => {
for (const key in data) {
localStorage.setItem(key, data[key]);
}
}, localStorageData);
}catch (error){
console.error('An error occurred:',error)
}
await page.goto(productUrl);
// Wait for the "Add to Cart" button to be available and click it
try{
await page.waitForSelector('.add-to-cart-button',{ timeout: 300000 });
await page.click('.add-to-cart-button');
console.log('Item added to cart');
await page.waitForSelector('button.btn-primary[data-track="Checkout - Top"]',{ timeout: 300000 });
await page.click('button.btn-primary[data-track="Checkout - Top"]');
console.log('Checkout button clicked');
}catch (error){
console.error('An error occurred:',error)
}
}
async function fetchGraphQL(zip, store, query) { async function fetchGraphQL(zip, store, query) {
const body = { const body = {
query, query,
@ -106,9 +168,11 @@ async function pollStore(zip, store) {
found = true; found = true;
const productUrl = getProductUrl(skuId) const productUrl = getProductUrl(skuId)
console.log(productUrl) console.log(productUrl)
open(productUrl)
winningResult = { skuId, zip, store, buttonState, data }; winningResult = { skuId, zip, store, buttonState, data };
await playAudioFile('./alarm.wav'); const openPromise = open(productUrl);
const addToCartPromise = addToCart(productUrl);
await open('./alarm.wav');
await addToCartPromise
return winningResult; return winningResult;
} }
} else { } else {
@ -130,7 +194,6 @@ async function runAllPollers() {
const result = await Promise.race(pollers); const result = await Promise.race(pollers);
console.log("Found a store with available button state:"); console.log("Found a store with available button state:");
console.log(JSON.stringify(result, null, 2)); console.log(JSON.stringify(result, null, 2));
process.exit(0);
} }
runAllPollers(); runAllPollers();

@ -0,0 +1,64 @@
import puppeteer from 'puppeteer-extra';
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
import AnonymizeUAPlugin from 'puppeteer-extra-plugin-anonymize-ua';
import AdblockerPlugin from 'puppeteer-extra-plugin-adblocker';
import fs from 'fs';
puppeteer.use(StealthPlugin());
puppeteer.use(AnonymizeUAPlugin());
puppeteer.use(
AdblockerPlugin({
blockTrackers: true,
}
));
const browser = await puppeteer.launch({
headless: false,
defaultViewport: null,
ignoreDefaultArgs: ["--disable-extensions"],
dumpio: true,
args: ["--start-maximized", "--no-sandbox", "--disable-setuid-sandbox"],
executablePath: "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
});
const page = await browser.newPage();
await page.setViewport({ width: 1280, height: 800 });
await page.goto('https://www.bestbuy.com/identity/global/signin');
// // Wait for the login form to be available and fill it in
// await page.waitForSelector('#fld-e');
// // Wait for the "Sign in with Google" button to be available and click it
// await page.waitForSelector('button[aria-labelledby="button-label"]');
// await page.click('button[aria-labelledby="button-label"]');
// // Wait for navigation after clicking the button
// await page.waitForNavigation();
// // Uncomment and replace with your credentials
// // await page.type('#fld-e', 'your-email@example.com'); // Replace with your email
// // await page.type('#fld-p1', 'your-password'); // Replace with your password
// // await page.click('.cia-form__controls__submit');
// Wait for navigation after login -- you have 1 minute!
await new Promise(resolve => setTimeout(resolve, 60000));
// Save cookies
const cookies = await page.cookies();
fs.writeFileSync('./cookies.json', JSON.stringify(cookies, null, 2));
// Save local storage data
const localStorageData = await page.evaluate(() => {
let json = {};
for (let i = 0; i < localStorage.length; i++) {
let key = localStorage.key(i);
json[key] = localStorage.getItem(key);
}
return json;
});
fs.writeFileSync('./localStorage.json', JSON.stringify(localStorageData, null, 2));
console.log('Login session saved.');
await browser.close();

1697
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -13,6 +13,11 @@
"dependencies": { "dependencies": {
"audic": "^3.0.2", "audic": "^3.0.2",
"node-fetch": "^3.3.2", "node-fetch": "^3.3.2",
"open": "^10.1.0" "open": "^10.1.0",
"puppeteer": "^24.1.1",
"puppeteer-extra": "^3.3.6",
"puppeteer-extra-plugin-adblocker": "^2.13.6",
"puppeteer-extra-plugin-anonymize-ua": "^2.4.6",
"puppeteer-extra-plugin-stealth": "^2.11.2"
} }
} }

Loading…
Cancel
Save