tauri-apps / tauri-apps/plugins-workspace

[log] getCallerLocation reports wrong caller on WebKit when async functions are compiled to generators

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

Description

## Description

`getCallerLocation()` in `plugins/log/guest-js/index.ts` reports the wrong source location on WebKit (macOS/iOS Tauri webview). The log target always shows the plugin's own file (e.g. `index.js:154`) instead of the actual caller file.

## Environment

- Platform: macOS (WebKit/JavaScriptCore)
- tauri-plugin-log: 2.8.0
- Bundler: Vite 6.x
- Tauri: 2.x

## Root Cause

The compiled `dist-js/index.js` transforms `async function info()` into generator-based code, which introduces additional internal stack frames in WebKit's JavaScriptCore engine. The current implementation uses hardcoded frame indices (`lines[3]` for V8, `filtered[2]` for WebKit) that do not account for these extra frames.

### Current behavior

```
[INFO][webview:info@node_modules/@tauri-apps/plugin-log/dist-js/index.js:154:14] my log message
```

### Expected behavior

```
[INFO][webview:logUpgrade@src/app/store/myStore.ts:14:10] my log message
```

## Proposed Fix

Instead of relying on fixed frame indices, detect the plugin's own file from the first stack frame, then skip all frames belonging to that file and return the first external (caller) frame. This is robust regardless of how many internal frames exist (async generators, bundler wrappers, etc.).

Additionally, strip URL scheme + authority prefix (`http://host:port/`, `tauri://host/`) from file paths in the returned location for cleaner log output.

I have a working patch verified on macOS WebKit and will submit a PR shortly.

## Steps to Reproduce

1. Create a Tauri v2 app on macOS
2. Call `info("test message")` from `@tauri-apps/plugin-log` in any `.ts` file
3. Check the log file at `~/Library/Logs//logs.log`
4. Observe that the target field shows the plugin's own `index.js:154` instead of the actual caller file and line number

Contributor guide

Open the contributing guide

Research direction

Start in plugins/log/guest-js/index.ts and inspect getCallerLocation(), then compare its fixed stack-frame selection with the compiled dist-js/index.js behavior on WebKit. Reproduce the issue from a Tauri v2 app by calling info() from a TypeScript file. Done means the log target reports the external caller location, with URL scheme and authority removed.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
observability
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.