Getting local PDF's URL using a Content Script
When accessing pdfs for Google Chrome, the browser uses its own extension to read and show PDFs. I would like to get the URL from a local source file "file:///C:/Users/Test/Desktop/test%20extension/test.pdf" using a content script.
My goal is to eventually get the text of this PDF so that I can read through it, and the pdf.js library I am using requires the URL of the pdf.
On the chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html file, the below element holds this data.
<embed id="plugin" type="application/x-google-chrome-pdf" src="file:///C:/Users/Test/Desktop/test%20extension/test.pdf" stream-url="blob:chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/e268f61a-7f6c-44ab-9218-7193dc73a783" headers="" background-color="0xFF525659" top-toolbar-height="56" javascript="allow" full-frame="">
I have embedded my content script as shown below in manifest.json:
"content_scripts": [
{
"matches": ["*://*/*.pdf"],
"js": ["contentScript.js"]
}
],
My content script has the following code which I believe should pull this URL:
var fileUrl = document.getElementById('plugin').src;
console.log('The file URL is : ' + fileUrl);
My goal is to get the console.log() above to return the fileUrl ("file:///C:/Users/Test/Desktop/test%20extension/test.pdf"). Does anyone have suggestions on how to do this? Is it possible that I am not calling my content script correctly?
javascript pdf google-chrome-extension content-script
add a comment |
When accessing pdfs for Google Chrome, the browser uses its own extension to read and show PDFs. I would like to get the URL from a local source file "file:///C:/Users/Test/Desktop/test%20extension/test.pdf" using a content script.
My goal is to eventually get the text of this PDF so that I can read through it, and the pdf.js library I am using requires the URL of the pdf.
On the chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html file, the below element holds this data.
<embed id="plugin" type="application/x-google-chrome-pdf" src="file:///C:/Users/Test/Desktop/test%20extension/test.pdf" stream-url="blob:chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/e268f61a-7f6c-44ab-9218-7193dc73a783" headers="" background-color="0xFF525659" top-toolbar-height="56" javascript="allow" full-frame="">
I have embedded my content script as shown below in manifest.json:
"content_scripts": [
{
"matches": ["*://*/*.pdf"],
"js": ["contentScript.js"]
}
],
My content script has the following code which I believe should pull this URL:
var fileUrl = document.getElementById('plugin').src;
console.log('The file URL is : ' + fileUrl);
My goal is to get the console.log() above to return the fileUrl ("file:///C:/Users/Test/Desktop/test%20extension/test.pdf"). Does anyone have suggestions on how to do this? Is it possible that I am not calling my content script correctly?
javascript pdf google-chrome-extension content-script
Local files are special so you need an additional match pattern that starts with file:// and when your extension is installed from the web store the users will have to enable the file access toggle in extension's details on chrome://extensions page.
– wOxxOm
Jan 2 at 4:13
Thank you so much! Changing the match pattern to "file://" did the trick!
– Brendon Gallagher
Jan 4 at 2:41
add a comment |
When accessing pdfs for Google Chrome, the browser uses its own extension to read and show PDFs. I would like to get the URL from a local source file "file:///C:/Users/Test/Desktop/test%20extension/test.pdf" using a content script.
My goal is to eventually get the text of this PDF so that I can read through it, and the pdf.js library I am using requires the URL of the pdf.
On the chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html file, the below element holds this data.
<embed id="plugin" type="application/x-google-chrome-pdf" src="file:///C:/Users/Test/Desktop/test%20extension/test.pdf" stream-url="blob:chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/e268f61a-7f6c-44ab-9218-7193dc73a783" headers="" background-color="0xFF525659" top-toolbar-height="56" javascript="allow" full-frame="">
I have embedded my content script as shown below in manifest.json:
"content_scripts": [
{
"matches": ["*://*/*.pdf"],
"js": ["contentScript.js"]
}
],
My content script has the following code which I believe should pull this URL:
var fileUrl = document.getElementById('plugin').src;
console.log('The file URL is : ' + fileUrl);
My goal is to get the console.log() above to return the fileUrl ("file:///C:/Users/Test/Desktop/test%20extension/test.pdf"). Does anyone have suggestions on how to do this? Is it possible that I am not calling my content script correctly?
javascript pdf google-chrome-extension content-script
When accessing pdfs for Google Chrome, the browser uses its own extension to read and show PDFs. I would like to get the URL from a local source file "file:///C:/Users/Test/Desktop/test%20extension/test.pdf" using a content script.
My goal is to eventually get the text of this PDF so that I can read through it, and the pdf.js library I am using requires the URL of the pdf.
On the chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html file, the below element holds this data.
<embed id="plugin" type="application/x-google-chrome-pdf" src="file:///C:/Users/Test/Desktop/test%20extension/test.pdf" stream-url="blob:chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/e268f61a-7f6c-44ab-9218-7193dc73a783" headers="" background-color="0xFF525659" top-toolbar-height="56" javascript="allow" full-frame="">
I have embedded my content script as shown below in manifest.json:
"content_scripts": [
{
"matches": ["*://*/*.pdf"],
"js": ["contentScript.js"]
}
],
My content script has the following code which I believe should pull this URL:
var fileUrl = document.getElementById('plugin').src;
console.log('The file URL is : ' + fileUrl);
My goal is to get the console.log() above to return the fileUrl ("file:///C:/Users/Test/Desktop/test%20extension/test.pdf"). Does anyone have suggestions on how to do this? Is it possible that I am not calling my content script correctly?
javascript pdf google-chrome-extension content-script
javascript pdf google-chrome-extension content-script
asked Jan 2 at 3:40
Brendon GallagherBrendon Gallagher
12
12
Local files are special so you need an additional match pattern that starts with file:// and when your extension is installed from the web store the users will have to enable the file access toggle in extension's details on chrome://extensions page.
– wOxxOm
Jan 2 at 4:13
Thank you so much! Changing the match pattern to "file://" did the trick!
– Brendon Gallagher
Jan 4 at 2:41
add a comment |
Local files are special so you need an additional match pattern that starts with file:// and when your extension is installed from the web store the users will have to enable the file access toggle in extension's details on chrome://extensions page.
– wOxxOm
Jan 2 at 4:13
Thank you so much! Changing the match pattern to "file://" did the trick!
– Brendon Gallagher
Jan 4 at 2:41
Local files are special so you need an additional match pattern that starts with file:// and when your extension is installed from the web store the users will have to enable the file access toggle in extension's details on chrome://extensions page.
– wOxxOm
Jan 2 at 4:13
Local files are special so you need an additional match pattern that starts with file:// and when your extension is installed from the web store the users will have to enable the file access toggle in extension's details on chrome://extensions page.
– wOxxOm
Jan 2 at 4:13
Thank you so much! Changing the match pattern to "file://" did the trick!
– Brendon Gallagher
Jan 4 at 2:41
Thank you so much! Changing the match pattern to "file://" did the trick!
– Brendon Gallagher
Jan 4 at 2:41
add a comment |
1 Answer
1
active
oldest
votes
as @wOxxOm suggested, changing the "matches" pattern from
"matches": "*://*/*.pdf"
to
"matches": "file://*/*.pdf"
did the trick!!
Note that the suggestion was to add that as a second pattern, not change it. You may get both permissions when you're developing the extension because already-granted permissions are remembered between reloads, but it won't persist if you reinstall it.
– Xan
Jan 4 at 12:58
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54000962%2fgetting-local-pdfs-url-using-a-content-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
as @wOxxOm suggested, changing the "matches" pattern from
"matches": "*://*/*.pdf"
to
"matches": "file://*/*.pdf"
did the trick!!
Note that the suggestion was to add that as a second pattern, not change it. You may get both permissions when you're developing the extension because already-granted permissions are remembered between reloads, but it won't persist if you reinstall it.
– Xan
Jan 4 at 12:58
add a comment |
as @wOxxOm suggested, changing the "matches" pattern from
"matches": "*://*/*.pdf"
to
"matches": "file://*/*.pdf"
did the trick!!
Note that the suggestion was to add that as a second pattern, not change it. You may get both permissions when you're developing the extension because already-granted permissions are remembered between reloads, but it won't persist if you reinstall it.
– Xan
Jan 4 at 12:58
add a comment |
as @wOxxOm suggested, changing the "matches" pattern from
"matches": "*://*/*.pdf"
to
"matches": "file://*/*.pdf"
did the trick!!
as @wOxxOm suggested, changing the "matches" pattern from
"matches": "*://*/*.pdf"
to
"matches": "file://*/*.pdf"
did the trick!!
answered Jan 4 at 2:43
Brendon GallagherBrendon Gallagher
12
12
Note that the suggestion was to add that as a second pattern, not change it. You may get both permissions when you're developing the extension because already-granted permissions are remembered between reloads, but it won't persist if you reinstall it.
– Xan
Jan 4 at 12:58
add a comment |
Note that the suggestion was to add that as a second pattern, not change it. You may get both permissions when you're developing the extension because already-granted permissions are remembered between reloads, but it won't persist if you reinstall it.
– Xan
Jan 4 at 12:58
Note that the suggestion was to add that as a second pattern, not change it. You may get both permissions when you're developing the extension because already-granted permissions are remembered between reloads, but it won't persist if you reinstall it.
– Xan
Jan 4 at 12:58
Note that the suggestion was to add that as a second pattern, not change it. You may get both permissions when you're developing the extension because already-granted permissions are remembered between reloads, but it won't persist if you reinstall it.
– Xan
Jan 4 at 12:58
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54000962%2fgetting-local-pdfs-url-using-a-content-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Local files are special so you need an additional match pattern that starts with file:// and when your extension is installed from the web store the users will have to enable the file access toggle in extension's details on chrome://extensions page.
– wOxxOm
Jan 2 at 4:13
Thank you so much! Changing the match pattern to "file://" did the trick!
– Brendon Gallagher
Jan 4 at 2:41