← Back to Discord Forum

Cannot use a function that calls waitForEvent('filechooser') a second time successfully.

I have a test case that is checking 3 things (single selection single upload).

  1. That a filechooser will not accept multiple files.
  2. That it will accept one file.
  3. When a new file is uploaded it overwrites the old one.

The upload span psuedo-button (doesn't use an html input) itself is on a new page that gets generated when clicking a link from the main body so the page is generated fresh each time I select it. I've written the following function:

async function uploadFilesUsingFilechooser (logger, page, locator, filepath) {
    // Logging filepaths passed by the caller
    if (filepath.length == 1) {
        filepath = filepath[0];
        logger("Single file: " + filepath);
    } else {
        let i = 0;
        logger('Files to be uploaded: ');
        for (var file in filepath) {
            const msg = "File" + ++i + ": " + file;

    // Logging selector passed by the caller.
    logger("Locator: " + locator)

    try {
        const fileChooserPromise = page.waitForEvent('filechooser');
        await page.locator(locator).click();
        const fileChooser = await fileChooserPromise;
        await fileChooser.setFiles(filepath);
    } catch (e) {
        return e.message;

    return "Success";


The problem is it works great the first time, but any other times that it runs it fails with the following (even though the uploader page has not changed):

fileChooser.setFiles: Protocol error (Page.describeNode): error in channel "content::6442450948/6442450985/55": exception while running method "describeNode" in namespace "page": frame.domWindow() is undefined _describeNode@chrome://juggler/content/content/PageAgent.js:419:30

Any help would be appreciated.

This thread is trying to answer question "Why does the function that calls waitForEvent('filechooser') fail on subsequent runs and how can it be fixed?"

0 replies

Related Discord Threads

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.