Skip to content

[Question]: Weird case of .pdf download off Chrome's PDF Viewer #7830

@mdkgr

Description

@mdkgr

Hello,

I am on Playwright 1.13, on Node 14.15, on Windows 10 x64 19043.1110. I'm a new programmer in general, this is my first issue ever.

My issue is related to #3509 "[Question] Is it possible to set AlwaysOpenPdfExternally".

I'm trying to capture a .pdf that opens on Chrome's default PDF Viewer. There's a website on which I've managed to download .pdf files off the default PDF Viewer, but there's a specific instance on that website where I can't understand why I cannot download a file in the same manner, while on the surface they appear to be downloaded in exactly the same way.

The files I've managed to download derived from pages that spawned independently (exogenously) from my primary Chrome instance (and not as new Tabs), while the file I cannot download derives from a page that opens as a new Tab in my currently running Chrome instance. I restate that all these files open Chrome's default PDF Viewer. My Chrome context looks like this:

const tmpDir = fs.mkdtempSync(`${os.tmpdir()}${path.sep}`);
fs.mkdirSync(`${tmpDir}/userdir/Default`, {recursive: true});

const defaultPreferences = {
    plugins: {
        always_open_pdf_externally: true,
    },
}

fs.writeFileSync(`${tmpDir}/userdir/Default/Preferences`, JSON.stringify(defaultPreferences));

const context = await chromium.launchPersistentContext(`${tmpDir}/userdir`, {
    acceptDownloads: true,
    headless: false,
    viewport: {
        width: 1440,
        height: 900
    },
});

This is the code around the the page on which I click the appropriate buttons that trigger the spawn of the pages from which the downloads derive:

await page.waitForSelector("td:nth-of-type(6) > input[name='PB_EKKATH_PDF']");
const [ekkPage] = await Promise.all([
    context.waitForEvent('page'),
    page.click('td:nth-of-type(6) > input[name=\'PB_EKKATH_PDF\']')
]);
await ekkPage.on('download', download => download.saveAs(`./temp/ΕΚΚ 2019_${onoma}.pdf`))
await ekkPage.waitForLoadState('networkidle');

When trying the same code on the problematic file, the program crashes.

I tried a lot of different solutions and tried to skim throught all the information on Playwright’s docs, and especially on the “Downloads” section, with no success.

My last thought was to try page.route() to intercept the .pdf while it’s being downloaded, but I don't know how to implement a solution around that method (too new in programming for that). @pavelfeldman almost gave an answer for that on #3509, and I couldn’t find any more info on the Web.

Here’s a short video that shows two files being downloaded and the third, which is the problematic one, where the program opens a new Tab and crashes:

https://youtu.be/OsDDdk12hqg

P.S.: Many edits occured to fix formatting and general text positioning

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions