Discussions » Development

Can't interact with pdf file elements

§
Posted: 2021-07-31
Edited: 2021-07-31
I can't get the page number of a pdf file on edge chromium, I thought I would need unsafeWindow but that didn't change anything, then I thought I wasn't trying to do it on the correct time so I added the alert inside the setInterval, but I keep getting null all the time.

// ==UserScript==
// @name p
// @namespace p
// @version 0.1
// @include file://*
// @include *.pdf
// @include *.pdf?*
// @include *.pdf#*
// @include /file:\/\/\/.*(.pdf)/
// @run-at document-end
// @grant GM_getValue
// @grant GM_setValue
// @grant unsafeWindow
// ==/UserScript==

(function() {
'use strict';
setInterval(function(){
alert(unsafeWindow.document.querySelector("input#pageselector").value );
}, 1000);
})();
§
Posted: 2021-07-31

I think I know how to do this. Wait a few minutes

wOxxOmMod
§
Posted: 2021-07-31

What you see in devtools is DOM of the built-in chrome extension that shows PDF files (its URL and id is shown in the title of devtools). Userscripts can't run there and can't access those elements. The only thing you can do is to use the very limited communication API, which among a few useless things allows reading the currently selected text: https://stackoverflow.com/a/61076939/3959875

§
Posted: 2021-07-31

Nevermind, he is right

§
Posted: 2021-07-31
Edited: 2021-07-31
@wOxxOm
Yeah I supposed that was the case, that's sad.

@Konf
Thanks for the try.

Post reply

Sign in to post a reply.