Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lost some images when using single-file-bundle.js in puppeteer #1658

Open
harrisoff opened this issue Jan 11, 2025 · 1 comment
Open

Lost some images when using single-file-bundle.js in puppeteer #1658

harrisoff opened this issue Jan 11, 2025 · 1 comment

Comments

@harrisoff
Copy link

Describe the bug

I was trying to use singlefile in my puppeteer code and in some sites it lost some images.

To Reproduce

This issue can be reproduced in https://image.baidu.com/

I got correct result when using chrome extension:

image

But with my codes:

image

Minimal reproducible codes:

const fs = require('fs')
const puppeteer = require('puppeteer')

// downloaded from https://github.com/gildas-lormeau/single-file-cli/blob/master/lib/single-file-bundle.js
// and modified its way to export, making it a cjs module
const { script } = require('./lib/single-file-bundle')

;(async () => {
  const browser = await puppeteer.launch({
    defaultViewport: {
        width: 940,
        height: 700
    },
    // in headful mode I can see all images are loaded
    // but still lost those images
    // headless: false
  })

  const pages = await browser.pages();
  const page = pages[0];

  await page.evaluateOnNewDocument(script);

  await page.goto('https://image.baidu.com/', {
    waitUntil: ['networkidle0']
  })
  // tried to sleep some times here but not working

  const pageData = await page.evaluate(async () => {
    // I guess that some configs are needed so I tried to use the DEFAULT_CONFIG in
    // https://github.com/gildas-lormeau/SingleFile/blob/master/src/core/bg/config.js#L52
    // but not working
    return await singlefile.getPageData({})
  });

  fs.writeFileSync(`./test-${new Date().getTime()}.html`, pageData.content, { encoding: 'utf-8' })

  await browser.close()
})()

Expected behavior

Puppeteer gets the same result as chrome extension

Screenshots

Environment

  • OS: mbp m1 Sonoma 14.3.1
  • Browser: Chrome
  • Version: 131.0.6778.140

Additional context

@harrisoff
Copy link
Author

single-file-cli has this issue too

npx single-file "https://image.baidu.com/"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant