New issue
Advanced search Search tips
Starred by 1 user

Issue metadata

Status: WontFix
Owner: ----
Closed: Nov 2017
EstimatedDays: ----
NextAction: ----
OS: Linux , Windows , Chrome , Mac
Pri: 2
Type: Bug-Regression

Sign in to add a comment

Issue 777814: Can't postMessage to PDF plugin from a contentScript(but still works from console)

Reported by, Oct 24 2017

Issue description

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:56.0) Gecko/20100101 Firefox/56.0

Steps to reproduce the problem:
1. Download my Trufflepiggy - Quick Search extension:
2. Go to a website with a example pdf e.g.:
3. Open console 
4. Select something within the PDF
5. You gonna see an error that document.querySelector().postMessage is not a function on Chrome Canary (it probably started with v61 and is now also reproduceable since Opera v48). I  used this to post a message to the chrome PDF plugin and retrieve the selected text for my extension.
6. Let the text still selected and enter in your console(focus on top):
document.querySelector("[type='application/pdf']").postMessage({type: "getSelectedText"},"*");
and press ENTER.
7. The postMessage gets successfully sent and a piggy nose appear above your PDF selection.

What is the expected behavior?
Post a message from contentScript via document.querySelector("[type='application/pdf']").postMessage({type: "getSelectedText"},"*"); 

What went wrong?
document.querySelector("[type='application/pdf']").postMessage({type: "getSelectedText"},"*"); throws a is-not-a-function-error from contentScript.

Did this work before? Yes 60

Chrome version: <Copy from: 'about:version'>  Channel: canary
OS Version: OS X 10.12
Flash Version: 

It might has also worked on a minor 61 version. Just noticed the error yesterday and spent a few hours to find a fix on my side but no chance. Also Opera worked fine til the update today to 48.0.2685.50.
Bildschirmfoto 2017-10-24 um 12.54.16.png
177 KB View Download

Comment 1 by, Oct 24 2017

The error occurs on all desktop OS. Unfortunately I can't change that anymore.

Comment 2 by, Oct 24 2017

You can try to insert postMessage code in a <script> element so that it runs in page context:

Comment 3 by, Oct 24 2017

Components: -Blink Internals>Plugins>PDF
Summary: Can't postMessage to PDF plugin from a contentScript(but still works from console) (was: document.querySelector().postMessage throws not a function error from a contentScript(but still works from console))
I seem to recall dsinclair mentioning something about postMessage to PDF being removed, but I can't find any details.  Dan?

Comment 4 by, Oct 24 2017


Comment 5 by, Oct 24 2017

Status: Untriaged (was: Unconfirmed)
I don't think this was removed. We'll triage on our side and see what's going on.

Comment 6 by, Oct 24 2017

Thank you very much for looking into this issue.

@woxxom: thanks for the suggestion. If possible I would like to keep everything in my contentScript. My code worked great for over a year now.

Can't wait to hear back from you Dan and Rybers.

Greetings from Vienna,


Comment 7 by, Oct 30 2017

Labels: OS-Linux
Tried on Linux and I got the sad face console error. Will try to track this down soon, so the piggy find its truffles.

Comment 9 by, Nov 2 2017

this is working as intended. The JS object corresponding to the plugin is only available to the page, not to extensions (as it used to be in the past, but that was a bug)

Comment 10 by, Nov 2 2017

@Jochen: Ok, I see. So this means the current behaviour gonna stay, right?

So the only possibility now to get the text selection within a PDF is via a context menu extension, correct?

Thank you.

Comment 11 by, Nov 2 2017

Reporter@, you can simply run the code in page context:

function getSelectedText() {
  return new Promise(resolve => {
    window.addEventListener('message', function onMessage(e) {
      if (e.origin === 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai' &&
 && === 'getSelectedTextReply') {
        window.removeEventListener('message', onMessage);
    const script = document.createElement('script');
    document.documentElement.appendChild(script).text =
      `plugin.postMessage({type: 'getSelectedText'}, '*')`;

Usage: getSelectedText().then(text => { ... });

Comment 12 by, Nov 2 2017

@woxxom: right - totally forgot about the link you posted above. Gonna try to integrate this into my next extension update. Thanks.

Comment 13 by, Nov 2 2017

Status: WontFix (was: Untriaged)
Closing per comment #9.

Sign in to add a comment