tauri-apps / tauri-apps/plugins-workspace

[bug] Notifications not working in MacOS

Open
#2,143 25 comments 9 reactions 0 assignees View on GitHub
platform: macos plugin: notification type: bug
Dominant language
Rust
Stars
1.8k
Forks
602
Avg merge
4d 14h
Merged PRs (30d)
9

Description

### Describe the bug

I'm using Tauri with Svelte on a MacOS. But I'm having trouble with the `notification` module.

All Tauri APIs are allowlisted in `tauri.conf.json`.

**The code below runs and prints `permissionGranted` as `true` but the `sendNotification`s seem to have no effect.**
```
const notify = async () => {
let permissionGranted = await isPermissionGranted();
if (!permissionGranted) {
const permission = await requestPermission();
permissionGranted = permission === "granted";
}
if (permissionGranted) {
sendNotification("Tauri is awesome!");
sendNotification({ title: "TAURI", body: "Tauri is awesome!" });
console.log(permissionGranted);
}
}

notify();
```
**I also tried using the Notifications API in the Tauri console itself but nothing happens and the created Notification object has no properties.**
```js
Notification.permission; // "granted"
const n = new Notification("New Message", { body: "hello" }); // {} empty object
```

### Reproduction

1. `npm create tauri-app` and initiate with Svelte.
2. `cd` into directory and `npm install`.
3. Add in [notifications logic](https://tauri.app/v1/api/js/modules/notification#sendnotification) to script.
4. `npm run tauri dev`.
5. Notifications are not sent.

### Expected behavior

Notification sent to MacOS.

### Platform and versions

Environment
› OS: Mac OS 12.4.0 X64
› Node.js: 17.2.0
› npm: 8.13.2
› pnpm: 6.11.0
› yarn: 1.22.15
› rustup: 1.25.1
› rustc: 1.62.0
› cargo: 1.62.0
› Rust toolchain: stable-x86_64-apple-darwin

Packages
› @tauri-apps/cli [NPM]: 1.0.5
› @tauri-apps/api [NPM]: 1.0.2
› tauri [RUST]: 1.0.5,
› tauri-build [RUST]: 1.0.4,
› tao [RUST]: 0.12.2,
› wry [RUST]: 0.19.0,

App
› build-type: bundle
› CSP: unset
› distDir: ../public
› devPath: http://localhost:8080/
› framework: Svelte
› bundler: Rollup

### Stack trace

_No response_

### Additional context

**tauri.conf.json**
```json
{
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
"build": {
"beforeBuildCommand": "npm run build",
"beforeDevCommand": "npm run dev",
"devPath": "http://localhost:8080",
"distDir": "../public"
},
"package": {
"productName": "d",
"version": "0.1.0"
},
"tauri": {
"allowlist": {
"all": true
},
"bundle": {
"active": true,
"category": "DeveloperTool",
"copyright": "",
"deb": {
"depends": []
},
"externalBin": [],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"identifier": "com.tauri.dev",
"longDescription": "",
"macOS": {
"entitlements": null,
"exceptionDomain": "",
"frameworks": [],
"providerShortName": null,
"signingIdentity": null
},
"resources": [],
"shortDescription": "",
"targets": "all",
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"timestampUrl": ""
}
},
"security": {
"csp": null
},
"updater": {
"active": false
},
"windows": [
{
"fullscreen": false,
"height": 600,
"resizable": true,
"title": "d",
"width": 800
}
]
}
}
```

**package.json**
```json
{
"name": "tauri-notification-test",
"version": "1.0.0",
"private": true,
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
"start": "sirv public --no-clear",
"tauri": "tauri"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.0.0",
"@tauri-apps/cli": "^1.0.5",
"rollup": "^2.3.4",
"rollup-plugin-css-only": "^3.1.0",
"rollup-plugin-livereload": "^2.0.0",
"rollup-plugin-svelte": "^7.0.0",
"rollup-plugin-terser": "^7.0.0",
"svelte": "^3.0.0"
},
"dependencies": {
"@tauri-apps/api": "^1.0.2",
"sirv-cli": "^2.0.0"
}
}
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue using the notification code, tauri.conf.json, package.json, and the reported macOS environment. Start by tracing the notification API entry point and its macOS path, then compare the native and browser Notification behaviors described. Done means both sendNotification calls produce visible notifications on macOS.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, macos
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.