Local javascript website (file:///) confuses notification permissions on Chrome, Edge
I'm building a companion website/app for the call center I work at which does a bunch of handy things including tracking breaks, and that's where I'm having issues.
This "site" will be stored as an html file the user keeps on their computer (I can't host it elsewhere for security reasons), and that seems to be the core of the problem as I'm trying to enable desktop alerts.
Here's what I'm using for requesting notification permission:
document.addEventListener('DOMContentLoaded', function () {
if (!Notification) {
alert('Desktop notifications not available in this browser.');
return;
}
if (Notification.permission !== "granted")
Notification.requestPermission();
});
function notifyMe() {
if (Notification.permission !== "granted")
Notification.requestPermission();
else {
var notification = new Notification('Notification title', {
body: "Notification",
});
}
}
...Which I found in another thread here.
Problem is, as a local file, Chrome will never acknowledge it as having permission: I can click "approve" or "block" and nothing happens. If I manually add "file:///*" to Chrome's allowed sites, it will then receive notifications (it won't if I manually add the entire local address, however). Edge will add "file:" to its approved list but this doesn't work and cannot be edited.
I might just be out of luck here, as I want to get notifications working with a single button click for approval in Chrome (and they won't work at all in Edge).
Is there a way to specify the address you want the browser to add to the approved list? I can see a number of potential security issues with doing that, but it might be the only thing that will resolve this.
Thanks in advance!
javascript browser permissions notifications local
add a comment |
I'm building a companion website/app for the call center I work at which does a bunch of handy things including tracking breaks, and that's where I'm having issues.
This "site" will be stored as an html file the user keeps on their computer (I can't host it elsewhere for security reasons), and that seems to be the core of the problem as I'm trying to enable desktop alerts.
Here's what I'm using for requesting notification permission:
document.addEventListener('DOMContentLoaded', function () {
if (!Notification) {
alert('Desktop notifications not available in this browser.');
return;
}
if (Notification.permission !== "granted")
Notification.requestPermission();
});
function notifyMe() {
if (Notification.permission !== "granted")
Notification.requestPermission();
else {
var notification = new Notification('Notification title', {
body: "Notification",
});
}
}
...Which I found in another thread here.
Problem is, as a local file, Chrome will never acknowledge it as having permission: I can click "approve" or "block" and nothing happens. If I manually add "file:///*" to Chrome's allowed sites, it will then receive notifications (it won't if I manually add the entire local address, however). Edge will add "file:" to its approved list but this doesn't work and cannot be edited.
I might just be out of luck here, as I want to get notifications working with a single button click for approval in Chrome (and they won't work at all in Edge).
Is there a way to specify the address you want the browser to add to the approved list? I can see a number of potential security issues with doing that, but it might be the only thing that will resolve this.
Thanks in advance!
javascript browser permissions notifications local
1
what isNotification
? (Also, if you can't host the file on a local server, using html/javascript for this seems like entirely the wrong approach. Better off using another language and compiling/converting it into an executable.)
– Robin Zigmond
Nov 13 '18 at 20:09
"Notification" displays desktop notifications, but only if the page has been explicitly granted permission to do so. I realize another language might be better, but I'm using this project to teach myself JS as well as build a tool for increasing efficiency at my job.
– JLowther
Nov 13 '18 at 20:54
add a comment |
I'm building a companion website/app for the call center I work at which does a bunch of handy things including tracking breaks, and that's where I'm having issues.
This "site" will be stored as an html file the user keeps on their computer (I can't host it elsewhere for security reasons), and that seems to be the core of the problem as I'm trying to enable desktop alerts.
Here's what I'm using for requesting notification permission:
document.addEventListener('DOMContentLoaded', function () {
if (!Notification) {
alert('Desktop notifications not available in this browser.');
return;
}
if (Notification.permission !== "granted")
Notification.requestPermission();
});
function notifyMe() {
if (Notification.permission !== "granted")
Notification.requestPermission();
else {
var notification = new Notification('Notification title', {
body: "Notification",
});
}
}
...Which I found in another thread here.
Problem is, as a local file, Chrome will never acknowledge it as having permission: I can click "approve" or "block" and nothing happens. If I manually add "file:///*" to Chrome's allowed sites, it will then receive notifications (it won't if I manually add the entire local address, however). Edge will add "file:" to its approved list but this doesn't work and cannot be edited.
I might just be out of luck here, as I want to get notifications working with a single button click for approval in Chrome (and they won't work at all in Edge).
Is there a way to specify the address you want the browser to add to the approved list? I can see a number of potential security issues with doing that, but it might be the only thing that will resolve this.
Thanks in advance!
javascript browser permissions notifications local
I'm building a companion website/app for the call center I work at which does a bunch of handy things including tracking breaks, and that's where I'm having issues.
This "site" will be stored as an html file the user keeps on their computer (I can't host it elsewhere for security reasons), and that seems to be the core of the problem as I'm trying to enable desktop alerts.
Here's what I'm using for requesting notification permission:
document.addEventListener('DOMContentLoaded', function () {
if (!Notification) {
alert('Desktop notifications not available in this browser.');
return;
}
if (Notification.permission !== "granted")
Notification.requestPermission();
});
function notifyMe() {
if (Notification.permission !== "granted")
Notification.requestPermission();
else {
var notification = new Notification('Notification title', {
body: "Notification",
});
}
}
...Which I found in another thread here.
Problem is, as a local file, Chrome will never acknowledge it as having permission: I can click "approve" or "block" and nothing happens. If I manually add "file:///*" to Chrome's allowed sites, it will then receive notifications (it won't if I manually add the entire local address, however). Edge will add "file:" to its approved list but this doesn't work and cannot be edited.
I might just be out of luck here, as I want to get notifications working with a single button click for approval in Chrome (and they won't work at all in Edge).
Is there a way to specify the address you want the browser to add to the approved list? I can see a number of potential security issues with doing that, but it might be the only thing that will resolve this.
Thanks in advance!
javascript browser permissions notifications local
javascript browser permissions notifications local
asked Nov 13 '18 at 19:57
JLowtherJLowther
1
1
1
what isNotification
? (Also, if you can't host the file on a local server, using html/javascript for this seems like entirely the wrong approach. Better off using another language and compiling/converting it into an executable.)
– Robin Zigmond
Nov 13 '18 at 20:09
"Notification" displays desktop notifications, but only if the page has been explicitly granted permission to do so. I realize another language might be better, but I'm using this project to teach myself JS as well as build a tool for increasing efficiency at my job.
– JLowther
Nov 13 '18 at 20:54
add a comment |
1
what isNotification
? (Also, if you can't host the file on a local server, using html/javascript for this seems like entirely the wrong approach. Better off using another language and compiling/converting it into an executable.)
– Robin Zigmond
Nov 13 '18 at 20:09
"Notification" displays desktop notifications, but only if the page has been explicitly granted permission to do so. I realize another language might be better, but I'm using this project to teach myself JS as well as build a tool for increasing efficiency at my job.
– JLowther
Nov 13 '18 at 20:54
1
1
what is
Notification
? (Also, if you can't host the file on a local server, using html/javascript for this seems like entirely the wrong approach. Better off using another language and compiling/converting it into an executable.)– Robin Zigmond
Nov 13 '18 at 20:09
what is
Notification
? (Also, if you can't host the file on a local server, using html/javascript for this seems like entirely the wrong approach. Better off using another language and compiling/converting it into an executable.)– Robin Zigmond
Nov 13 '18 at 20:09
"Notification" displays desktop notifications, but only if the page has been explicitly granted permission to do so. I realize another language might be better, but I'm using this project to teach myself JS as well as build a tool for increasing efficiency at my job.
– JLowther
Nov 13 '18 at 20:54
"Notification" displays desktop notifications, but only if the page has been explicitly granted permission to do so. I realize another language might be better, but I'm using this project to teach myself JS as well as build a tool for increasing efficiency at my job.
– JLowther
Nov 13 '18 at 20:54
add a comment |
0
active
oldest
votes
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%2f53288572%2flocal-javascript-website-file-confuses-notification-permissions-on-chrome%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53288572%2flocal-javascript-website-file-confuses-notification-permissions-on-chrome%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
1
what is
Notification
? (Also, if you can't host the file on a local server, using html/javascript for this seems like entirely the wrong approach. Better off using another language and compiling/converting it into an executable.)– Robin Zigmond
Nov 13 '18 at 20:09
"Notification" displays desktop notifications, but only if the page has been explicitly granted permission to do so. I realize another language might be better, but I'm using this project to teach myself JS as well as build a tool for increasing efficiency at my job.
– JLowther
Nov 13 '18 at 20:54