9

How can I find the folder for chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai (the hidden "Chrome PDF viewer")?

I need to access these files and change its JavaScript to send me a message before printing a PDF.

Xan
  • 74,770
  • 16
  • 179
  • 206
HTarda
  • 91
  • 1
  • 1
  • 4

1 Answers1

12

It's an internal component of Chrome; it's not really a physical folder to navigate to, this is compiled into the Chrome's own files (specifically resources.pak - thanks, wOxxOm).

You can get the source code of that extension from the Chromium source, e.g. https://chromium.googlesource.com/chromium/src.git/+/71.0.3578.98/chrome/browser/resources/pdf - note that those still need compilation with the Closure Compiler, so not usable for modification as-is.

But suppose you do modify and compile it. Can you install your modified version? Yes and no.

While it is technically possible to override the extension by presenting an unpacked extension with a higher version and the same key in the manifest..

enter image description here

..it will not actually work like that, because the manifest uses elevated "private" permissions..

"permissions": [
  "chrome://resources/",
  "contentSettings",
  "metricsPrivate",
  "resourcesPrivate"
],
"content_security_policy": "script-src 'self' blob: filesystem: chrome://resources; object-src * blob: externalfile: file: filesystem: data:; plugin-types application/x-google-chrome-pdf",

..that can't be used from a non-internal extension:

enter image description here

So if you really wanted to modify the internal PDF viewer, you'd need to compile your own modified version of Chromium, or at the very least your own version of resources.pak. Probably not what you want to do.

Xan
  • 74,770
  • 16
  • 179
  • 206
  • 2
    FWIW, it's possible to rebundle the modified extension's js inside `resources.pak` which is relatively easy (grit-i18n, ChromePAK, pak_tools) compared to compiling chromium. – wOxxOm Dec 20 '18 at 16:01
  • By all means, please edit the answer to provide info about `resources.pak`! @wOxxOm (or add your own) – Xan Dec 20 '18 at 16:04
  • 1
    See the answer and comments here: [how to unpack resources.pak from google chrome?](//stackoverflow.com/q/10633357) – wOxxOm Dec 21 '18 at 07:45
  • 1
    Nice explanation, thanks. weavatools.com (https://chrome.google.com/webstore/detail/weava-highlighter-pdf-web/cbnaodkpfinfiipjblikofhlhlcickei?hl=en) has modified the Chrome PDF viewer and released their own plugin. When you view a pdf in chrome, weava's modified PDF viewer is used instead (chrome-extension://cbnaodkpfinfiipjblikofhlhlcickei/src/pdfviewer/web/viewer.html?file=). The whole process feels seamless. Maybe we can learn from this approach? – Kevin Jan 25 '19 at 14:01