-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(useWebNotification): prevent notifications when checking for support #4019
base: main
Are you sure you want to change the base?
Conversation
In this PR, we are still triggering a notification, which I believe is unreasonable for the users. On stackoverflow, I found that it throws an error when used, and the error message is as follows:
I found that when I use
Can we determine support based on the error message? If the error message contains:
Can we then assume that Of course, this is just my guess, as I do not have the corresponding device to test, so I am not sure about the priority of these two errors. |
Additionally, as of now, it still triggers two notifications because
and
This causes |
Can you tell me what environment you still trigger two notifications? // Notifications will show
const notification = new Notification('')
// Notifications will not show
const notification = new Notification('')
notification.onshow = () => {
notification.close()
} I also verified the changes in the development environment. Btw, I'm using Chrome under Windows. And vitepress may have a cache and not update to the latest code immediately(I'm having this issue). |
The fact that |
Sorry, I think I didn't describe it clearly just now. When I initialize, there are two notifications in my notification list. Here is my screen recording: QQ20240606-151916-HD.mp4The reason is that vueuse/packages/core/useSupported/index.ts Lines 4 to 13 in 4d868f5
|
Thanks for the reminder, but in this PR, I try to close the notification when it shows. And It works for me in Chrome under Windows. So this will not show the notification when const notification = new Notification('')
notification.onshow = () => {
notification.close()
} 20240606-160954.mp4Besides, I wonder if it's updated to the latest code, because I had this issue while debugging because of vitepress's caching. Also, I'll try to use the error type to do this soon, and if it works, I'll submit a new commit in this PR. |
I am on macOS and encountered this issue in the Arc browser. It seems that I did not reproduce it in Chrome. I am sure that I have updated to the latest code, as shown in the video: QQ20240606-170028-HD.mp4I am sure there is nothing wrong with my browser settings. Even if there is, we don't need to notify it. |
I tested
|
The two issues linked in function isNewNotificationSupported() {
if (!window.Notification || !Notification.requestPermission)
return false;
if (Notification.permission == 'granted')
throw new Error('You must only call this *before* calling Notification.requestPermission(), otherwise this feature detect would bug the user with an actual notification!');
try {
new Notification('');
} catch (e) {
if ([e.name](http://e.name/) == 'TypeError')
return false;
}
return true;
} However, that code throws an error which we can't do in |
Sorry for late, I think this should be the best solution right now. Let's have a try. |
Until this is merged, this is a workaround: if (window.Notification) {
window.Notification = class Notification extends window.Notification {
constructor(title: string, options?: NotificationOptions) {
super(title, options)
if (!title) {
this.onshow = () => {
this.close()
}
}
}
}
} |
Before submitting the PR, please make sure you do the following
fixes #123
).Description
fixes #4017
Additional context