Skip to content

Instantly share code, notes, and snippets.

@Tuarisa
Created June 16, 2021 13:28
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 Tuarisa/9c04101631cf7812c3e7ae51e1779cda to your computer and use it in GitHub Desktop.
Save Tuarisa/9c04101631cf7812c3e7ae51e1779cda to your computer and use it in GitHub Desktop.
// Require puppeteer
const puppeteer = require('puppeteer');
(async () => {
// Create an instance of the chrome browser
// But disable headless mode !
const browser = await puppeteer.launch({
headless: false
});
// Create a new page
const page = await browser.newPage();
// Configure the navigation timeout
await page.setDefaultNavigationTimeout(0);
await page.setRequestInterception(true);
page.on('request', request => {
// console.log(request);
request.continue();
});
page.on('requestfinished', async (request) => {
try {
const response = await request.response();
const url = response.url();
if (url.indexOf('api-partner')> -1) {
const json = await response.json();
console.log(JSON.stringify(json, null, 2))
}
} catch(e) {
//
}
});
// Navigate to some website e.g Our Code World
try {
await page.goto('https://open.spotify.com/track/5VNcKdmfAAsfbxbuo1Y7Vl?si=1303ef0370f3423e', { waitUntil: 'networkidle0' });
console.log('done');
}
catch(e) {
console.log(e);
}
finally {
await browser.close();
}
// Do your stuff
// ...
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment