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.

[Question] Is it possible to set AlwaysOpenPdfExternally

See original GitHub issue

Hi!

On creation of a browser or context (permanent or otherwise), is it possible to set the config value AlwaysOpenPdfExternally or the equivalent plugins.always_open_pdf_externally preference?

I’ve tried a kludgy solution that has me navigate to chrome://settings/content/pdfDocuments on load and click the option. But we need to use Chromium in headless to export PDFs of pages as well as download PDF files that the browser always opens in its embedded viewer… and there seems to be no way of getting the actual PDF content out of that viewer.

Any help would be appreciated.

Cheers, Wayne

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
waynerobinsoncommented, Aug 18, 2020

OK, after many hours of searching in the last 48 hours for a solution to this, I think I’ve managed to discover something soon after posting here that works.

Would anyone mind taking a look at this solution and seeing if it’s going to cause me any unexpected problems?

For each run:

const tmpDir = fs.mkdtempSync(`/tmp/pwtest`);
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(`${basePath}/userdir`, { acceptDownloads: true });

This seems to work and forces the browser to download files vs displaying them in the in-browser PDF viewer. I just want to make sure I’m not shooting myself in the foot by only having a tiny preferences file to start (although it gets filled-in on first start).

2reactions
ibratoevcommented, Dec 3, 2020

I hit the same problem today and the way I resolved it is by adding a download attribute before clicking the pdf link. Example:

    await page.$eval(pdfLinkSelector, (el) =>
        el.setAttribute('download', 'download'),
    );
Read more comments on GitHub >

github_iconTop Results From Across the Web

Always Open PDF files externally - Policy - Google Help
Chrome::AlwaysOpenPdfExternally. I noticed that following setting was active, so I tried changing the key to "0" and it worked.
Read more >
Open PDF Externally in IE Mode - Microsoft Community
We currently run IE Mode for a legacy application, and need PDF links to open in the native Adobe PDF application.
Read more >
Set 'Always open pdfs externally' in Edge GPO, but still allow ...
Is there a way to set this, but still allow the user to change if needed? The setting now is locked and does...
Read more >
Allow Microsoft Edge to download PDF files externally
This guide will show you how allow Microsoft Edge to download PDF files externally, instead of directly opening them in the browser.
Read more >
How to allow or block Google Chrome from opening PDF files ...
Double-click on the Always Open PDF files externally setting. ... you need to create a REG_DWORD value named AlwaysOpenPdfExternally and set ...
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