Can extension (content script) run in the default PDF viewer?

205 views
Skip to first unread message

Juraj M.

unread,
Jul 25, 2023, 12:05:21 PM7/25/23
to Chromium Extensions
I always thought the answer is no, but I see the Dark Reader actually works there.

But how? Is it just for CSS or is there some special way to inject it?

wOxxOm

unread,
Jul 26, 2023, 2:10:58 AM7/26/23
to Chromium Extensions, Juraj M.
When using the default PDF reader the tab is a normal web page that contains <object> with the internal viewer extension inside. The content scripts can run in the web page and modify DOM/CSS there, which is what Dark Reader does: if you inspect the page in devtools you'll see it simply inverts the colors of the object:

embed[type="application/pdf"][src="about:blank"] {
  filter: invert(100%) contrast(90%);
}

It doesn't run inside the viewer.

Juraj M.

unread,
Jul 26, 2023, 3:21:24 AM7/26/23
to Chromium Extensions, wOxxOm, Juraj M.
Thank you @wOxxOm for the explanation :)
I see now my extension is indeed executed inside the viewer... but since all events are consumed by the embed frame and all content is encapsulated inside, it's all futile :(
Reply all
Reply to author
Forward
0 new messages