question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

uploadFile works not everytime.

See original GitHub issue

I am trying to upload video to youporn.com with Puppeteer. My upload function looks like this:

async function uploadVideo(video, categories)
{
    
    youPornPage.on('console', consoleObj => console.log(consoleObj.text()));
    await youPornPage.setExtraHTTPHeaders({Referer: 'https://youporn.com'});
    await youPornPage.goto('https://youporn.com/upload/', {
        waitUntil: ['networkidle2'] 
    });      
    await youPornPage.waitFor(20000);
    let fileInput = await youPornPage.$(fileSelector);
    await fileInput.uploadFile(BASE_PATH+'/Videos/'+video.filename);
    await youPornPage.waitFor(3000);   
    let options2 = {
        path: 'after.png',
        fullPage: true
    }    
    await youPornPage.screenshot(options2);  
}

Browser configuration puppeteer.launch({headless: true, args:['--no-sandbox', '--disable-setuid-sandbox'], ignoreHTTPSErrors: true, dumpio: false }).then(async browser => { When I fill input file field with data, youporn then loads additional div where I can fill other information about video. The problem is, that this code works only once per 10-20 tries. I am sure that additional div is loaded when input file field’s change event is triggered. I tested and saw that uploadFile() function actually triggers that event, so I am guessing that there might be a problem with Javascript? Maybe some script is not loaded, but then I added 20sec waiting after page is loaded to make sure that javascript is loaded, and get the same results.

I tried to console log everything that I get when go to this webpage, and here are results:

Failed to load resource: the server responded with a status of 404 () Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME ServiceWorker scope: https://www.youporn.com/ Expected version: 2e48ca520f95d921bc2d7049a7e7c18a0e58d661 The resource https://fs.ypncdn.com/cb/assets/fonts/gothic.woff2?v=2e48ca520f95d921bc2d7049a7e7c18a0e58d661 was preloaded using link preload but not used within a few seconds from the window’s load event. Please make sure it has an appropriate as value and it is preloaded intentionally. The resource https://fs.ypncdn.com/cb/assets/fonts/yp.woff2?v=2e48ca520f95d921bc2d7049a7e7c18a0e58d661 was preloaded using link preload but not used within a few seconds from the window’s load event. Please make sure it has an appropriate as value and it is preloaded intentionally.

This is console log of the use case, when this code actually works correctly:

Failed to load resource: the server responded with a status of 404 () Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME A preload for ‘https://fs.ypncdn.com/cb/assets/fonts/yp.woff2?v=2e48ca520f95d921bc2d7049a7e7c18a0e58d661’ is found, but is not used because the request credentials mode does not match. Consider taking a look at crossorigin attribute. Failed to load resource: net::ERR_FAILED ServiceWorker scope: https://www.youporn.com/ Expected version: 2e48ca520f95d921bc2d7049a7e7c18a0e58d661 The resource https://fs.ypncdn.com/cb/assets/fonts/gothic.woff2?v=2e48ca520f95d921bc2d7049a7e7c18a0e58d661 was preloaded using link preload but not used within a few seconds from the window’s load event. Please make sure it has an appropriate as value and it is preloaded intentionally. The resource https://fs.ypncdn.com/cb/assets/fonts/yp.woff2?v=2e48ca520f95d921bc2d7049a7e7c18a0e58d661 was preloaded using link preload but not used within a few seconds from the window’s load event. Please make sure it has an appropriate as value and it is preloaded intentionally. Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME

Only difference I see is additional

Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME at the end.

Maybe someone could help me out, I am new to puppeteer, I guess that I missed some configuration but not sure where to look for. I have been trying to make this code consistent for two days.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
aslushnikovcommented, Nov 7, 2018

@dudeperfect95 a few things I noticed here:

  • your code doesn’t wait for the actual upload to happen; you might want to wait for the progress bar to fill?
  • instead of page.$ I’d recommend using page.waitForSelector - to await appearing of input and the div you’re interested in.

I can’t infer more from what I have; if you can share the whole script to play with I can check and see where and why it breaks.

@depsypher same here: if you can share your script so that I can play and debug it locally, it’d help a lot.

0reactions
paullewiscommented, Apr 17, 2020

Since #3463 is closed, and since we updated uploadFile to be more as expected (as of 532ae573d29063ffd081ed9ee340d71b25320dec) I’m going to close this issue, but please let us know if it’s not fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

File upload hangs on production code but works locally
1 Answer 1 ... You probably have pm2 with "watch" option enabled; and upload files inside watched directory. Then pm2 restarts application every ......
Read more >
12 Easy Ways to Fix Google Drive Upload Failed Issue in 2022
What would you do if Google Drive upload failed? Here in this article, 12 simple and free methods are provided for your reference....
Read more >
Fix problems uploading files on the OneDrive website
Sorry, OneDrive can't upload folders or empty files. To upload files to a new folder in OneDrive, first create the folder, and then...
Read more >
reRendering is not working after file upload us... - JBoss.org
Hi All Requirement : i am using rich faces 3.3.1 and i want to reRender panel(component in the same page) after uploading file...
Read more >
Inconsistent response to file type upload - WordPress.org
If you use this method, and you are not 'uploading files all the time' then I would simply add this to your config...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found