关闭。这个问题不能重现,或者是由错别字引起的。它当前不接受答案。想要改善这个问题吗?更新问题,使它成为Stack Overflow的主题。我正在使用puppeteer并尝试获取每个屏幕的屏幕快照,当我循环浏览每个设备的视图时,但这是说我将列表保存在其下的const是不可迭代的。确切的错误:TypeError: testedMobileDevices is not iterable我不明白为什么javascript无法遍历此列表以从列表中的每个设备生成每个页面的屏幕截图。这是我的脚本: //import devices from ‘./puppeteerDevices’ const puppeteer = require(‘puppeteer’); const devices = puppeteer.devices; const testedMobileDevices = devices[“Galaxy Note 3”, “Galaxy Note 3 landscape”, “Galaxy Note II”, “Galaxy Note II landscape”, “Galaxy S III”, “Galaxy S III landscape”, “Galaxy S5”, “Galaxy S5 landscape”, “iPad”, “iPad landscape”, “iPad Mini”, “iPad Mini landscape”, “iPad Pro”, “iPad Pro landscape”, “iPhone 4”, “iPhone 4 landscape”, “iPhone 5”, “iPhone 5 landscape”, “iPhone 6”, “iPhone 6 landscape”, “iPhone 6 Plus”, “iPhone 6 Plus landscape”, “iPhone 7”, “iPhone 7 landscape”, “iPhone 7 Plus”, “iPhone 7 Plus landscape”, “iPhone 8”, “iPhone 8 landscape”, “iPhone 8 Plus”, “iPhone 8 Plus landscape”, “iPhone SE”, “iPhone SE landscape”, “iPhone X”, “iPhone X landscape”, “iPhone XR”, “iPhone XR landscape”, “iPhone 11”, “iPhone 11 landscape”, “iPhone 11 Pro”, “iPhone 11 Pro landscape”, “iPhone 11 Pro Max”, “iPhone 11 Pro Max landscape”, “Nexus 10”, “Nexus 10 landscape”, “Nexus 4”, “Nexus 4 landscape”, “Nexus 5”, “Nexus 5 landscape”, “Nexus 5X”, “Nexus 5X landscape”, “Nexus 6”, “Nexus 6 landscape”, “Nexus 6P”, “Nexus 6P landscape”, “Nexus 7”, “Nexus 7 landscape”, “Pixel 2”, “Pixel 2 landscape”, “Pixel 2 XL”, “Pixel 2 XL landscape” ];
async function login() { const browser = await puppeteer.launch({ headless: true }); const page = await browser.newPage(); const username = '-------' const password = '------' const base_url = 'http://127.0.0.1:8000/' await page.setDefaultNavigationTimeout(0); await page.goto(`${base_url}/login`); //await page.type('[name=username]', username); //await page.type('[name=password]', password); await page.type('#username', username); await page.type('#password', password); await page.click('[type=submit]'); await page.waitForNavigation({ waitUntil: 'networkidle0' }); } async function test() { for (let device of testedMobileDevices) { await login(); const base_url = 'http://127.0.0.1:8000/' const urls = ['feed/', 'project/', 'mynetwork/'] const browser = await puppeteer.launch() const page = await browser.newPage() await page.setDefaultNavigationTimeout(0); await page.emulate(device); for (let url of urls) { await page.goto(`${ base_url }/${url}`); await page.screenshot({ path: "./screenshot.jpg", type: "jpeg", fullPage: true }); await page.waitForNavigation({ waitUntil: 'networkidle0' }); } } } test().then(() => { console.log("all done"); }).catch(err => { console.log(err); });