New issue
Advanced search Search tips

Issue 827499 link

Starred by 2 users

Issue metadata

Status: WontFix
Owner: ----
Closed: May 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Bug



Sign in to add a comment

Access Chrome PDF Viewer's loaded content through Chrome extension.

Reported by vaidas.p...@gmail.com, Mar 30 2018

Issue description

UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299

Steps to reproduce the problem:
1. 
2. 
3. 

What is the expected behavior?
To getSelection from the Built-in Chrome PDF Viewer's opened .pdf file and pass it to the extension I created for Chrome.

What went wrong?
There are no documentation or API on how to getSelection from Chrome PDF Viewer, and access it in an extension of chrome.

Did this work before? No 

Does this work in other browsers? No
 There are no official information about how to access content presented in a loaded PDF viewer's window.

https://groups.google.com/a/chromium.org/forum/#!topic/chromium-extensions/xiAMD7afiUA

Chrome version: 58.0.3029.110  Channel: stable
OS Version: 10.0
Flash Version: 

Please point me to the right direction, if this is the wrong place to report this.
 

Comment 1 by woxxom@gmail.com, Mar 30 2018

Your content script must communicate with the plugin in page context.
That is, you need to put the code into a 'script' element:

  document.body.appendChild(document.createElement('script')).text = '(' + (() => {
    addEventListener('message', function _(e) {
      if (e.data && e.data.type === 'getSelectedTextReply') {
        removeEventListener('message', _);
        alert('SUCCESS:\n' + e.data.selectedText);
      }
    });
    document.getElementById('plugin').postMessage({type: 'getSelectedText'}, '*');
  }) + ')()';

To transfer the data back into content script you can use DOM CustomEvent.
Similar example: https://stackoverflow.com/a/46870005
Labels: Needs-Milestone
Cc: rbasuvula@chromium.org
Components: Platform>Extensions
Labels: Needs-Feedback
@vaidas: Thanks for filing the issue! Could you please try once with comment #1 and if possible,Please create new profile without extensions and apps.Re-check once in latest chrome stable/canary and let us know the observations and sample steps of the issue which would help us to triage the issue further.

Thanks in Advance.
Comment #1 was a correct solution, selected text indeed get shown in the alert box. However, I have to criticize that we had to spend a whole week studying and rewriting the solution into more readable on the stackoverflow in the folowing link: https://stackoverflow.com/questions/49670116/why-unexpected-string-help-rewriting-ugly-code.

However, I still haven't transfered selected content to the content-script.
Due - I being really new to extension development.

I have tested the code snippet mentioned in comment #1 with a completely new profile, without any apps or extensions enabled.

It was tested in the stable Chrome Version 65.0.3325.181 (Official Build) (64-bit)
Status: WontFix (was: Unconfirmed)
Marking it as WontFix as per comment#4 provided by user.Feel free to raise a new issue if still facing.

Thank You!

Sign in to add a comment