Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Questions about Accessing Text Data in Chrome Reading Mode and PDF Documents

81 views
Skip to first unread message

Andrew Panchiy

unread,
Dec 10, 2024, 1:13:31 PM12/10/24
to Chromium Extensions

Dear Chrome Development Team,

I am currently developing a Chrome extension that interacts with user-selected text on various platforms. While extracting text from standard web pages and Google Docs is straightforward, I have encountered challenges when dealing with PDF documents.

Specifically, I noticed that the Chrome Reading Mode allows text from a PDF to be duplicated and selected, but there doesn’t seem to be a public API to access this functionality programmatically. Similarly, while I am aware that the contextMenus API with ContextType: "selection" can capture selected text, my use case requires retrieving the selection dynamically and programmatically without relying on user actions through the context menu.

With this in mind, I have two main questions:

  1. Are there any plans to make chrome.readingMode public, or to provide developers with a way to programmatically access text information from Reading Mode?

  2. Is there any roadmap for enabling APIs that allow extensions to interact with PDF documents more directly, particularly to programmatically access selected text within the PDF?

Thank you for considering these questions. Any insights or updates on these features would greatly enhance the functionality of Chrome extensions for working with text.

Best regards,
Andriy

Rajat Paharia

unread,
Dec 10, 2024, 3:08:07 PM12/10/24
to Chromium Extensions, Andrew Panchiy
Hi Andriy - 

woxxom's answer here for getting the selected text from a PDF still works: https://stackoverflow.com/questions/61076303/how-can-i-get-selected-text-in-pdf-in-javascript

best, - rajat

Andrew Panchiy

unread,
Dec 11, 2024, 6:04:51 AM12/11/24
to Chromium Extensions, Rajat Paharia, Andrew Panchiy
Thanks for the answer, I looked at this answer and it partially works. Currently this api can only return text from pages that have origin, in the case of local pdf documents, I get the error:
"Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('file://') does not match the recipient window's origin ('null')."

I would be glad if you could help me solve this issue, thanks again

Rajat Paharia

unread,
Dec 12, 2024, 9:56:08 AM12/12/24
to Chromium Extensions, Andrew Panchiy, Rajat Paharia
Yes, that solution doesn't work for local PDF documents. Access to file:// urls requires an additional explicit approval by the user that I didn't want to require: https://developer.chrome.com/docs/extensions/develop/concepts/declare-permissions#allow_access

I needed to make my own dedicated viewer page that users have to load their already downloaded PDF into: https://quickstart.asksteve.to/viewer/

All the source is in the page. - rajat

Reply all
Reply to author
Forward
0 new messages