Spaces:
Running
Running
Download test_canvas.js from veltrixcode/jsondb: direct link, hf CLI and curl.
- Browser
- Download file 2.65 kB
-
https://huggingface.co/spaces/veltrixcode/jsondb/resolve/main/test_canvas.js
- Command line
-
hf download hf://spaces/veltrixcode/jsondb/test_canvas.js
-
curl -L -o test_canvas.js https://huggingface.co/spaces/veltrixcode/jsondb/resolve/main/test_canvas.js
2.65 kB
| import puppeteer from 'puppeteer-core'; | |
| import fs from 'fs'; | |
| const parseNetscapeCookies = (text) => { | |
| const cookies = []; | |
| const lines = text.split('\n'); | |
| for (const line of lines) { | |
| if (!line.trim() || line.startsWith('#')) continue; | |
| const parts = line.split('\t'); | |
| if (parts.length >= 7) { | |
| cookies.push({ | |
| name: parts[5], | |
| value: parts[6].trim(), | |
| domain: parts[0], | |
| path: parts[2], | |
| secure: parts[3] === 'TRUE', | |
| expires: parseFloat(parts[4]) | |
| }); | |
| } | |
| } | |
| return cookies; | |
| }; | |
| async function testNetworkInterception() { | |
| const cookieText = fs.readFileSync('cookies.txt', 'utf8'); | |
| const cookies = parseNetscapeCookies(cookieText); | |
| const executablePath = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'; | |
| const browser = await puppeteer.launch({ | |
| executablePath, | |
| headless: true, | |
| args: ['--no-sandbox', '--disable-setuid-sandbox'] | |
| }); | |
| const page = await browser.newPage(); | |
| await page.setCookie(...cookies); | |
| let searchResponseData = null; | |
| console.log("Listening for Pathfinder query responses..."); | |
| page.on('response', async (response) => { | |
| const url = response.url(); | |
| if (url.includes('api-partner.spotify.com/pathfinder/v1/query')) { | |
| const request = response.request(); | |
| const postData = request.postData() || ''; | |
| // Check if it's the search request | |
| if (url.includes('search') || postData.includes('search') || postData.includes('Search') || url.includes('operationName=search')) { | |
| try { | |
| const text = await response.text(); | |
| const json = JSON.parse(text); | |
| console.log("FOUND SEARCH GRAPHQL RESPONSE!"); | |
| searchResponseData = json; | |
| } catch (e) { | |
| // Ignore parse errors or text errors | |
| } | |
| } | |
| } | |
| }); | |
| const query = "Kill Bill SZA"; | |
| console.log(`Navigating to search page for: ${query}...`); | |
| // Navigate directly to the search URL for the query | |
| const searchUrl = `https://open.spotify.com/search/${encodeURIComponent(query)}`; | |
| await page.goto(searchUrl, { waitUntil: 'networkidle2', timeout: 30000 }); | |
| // Wait another 5 seconds to ensure requests finish loading | |
| await new Promise(resolve => setTimeout(resolve, 5000)); | |
| console.log("Closing browser..."); | |
| await browser.close(); | |
| if (searchResponseData) { | |
| console.log("GraphQL Search Data (truncated):", JSON.stringify(searchResponseData, null, 2).substring(0, 1500)); | |
| } else { | |
| console.log("Search response not captured via network interception. Let's list all requests we saw:"); | |
| } | |
| } | |
| testNetworkInterception().catch(console.error); | |