Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
d1d1219
fix: improve script handling in execute commands for better serializa…
goosewobbler Apr 9, 2026
529b134
docs: remove tauri-playwright analysis document and update improvemen…
goosewobbler Apr 9, 2026
0130321
refactor(tauri): improve script handling in execute function for Tauri
goosewobbler Apr 9, 2026
d7d53e9
refactor(tauri): enhance script handling in execute function
goosewobbler Apr 9, 2026
bb4085b
refactor(electron): simplify script handling in execute function
goosewobbler Apr 9, 2026
f21d60a
refactor(tauri): enhance error handling in execute function
goosewobbler Apr 9, 2026
5f2526b
refactor(tauri): simplify script handling in execute function
goosewobbler Apr 9, 2026
4d80fcb
refactor(tauri): update script handling in execute function
goosewobbler Apr 9, 2026
1b6b4be
refactor(tauri): correct script wrapping in execute function
goosewobbler Apr 9, 2026
dd8b8a4
docs(tauri): clarify script serialization in execute function
goosewobbler Apr 9, 2026
bf638a7
refactor(tauri): enhance script execution logic in execute function
goosewobbler Apr 9, 2026
4210433
refactor(tauri): streamline script execution logic in execute function
goosewobbler Apr 9, 2026
cfcbdf3
refactor(tauri): improve argument handling in script execution
goosewobbler Apr 9, 2026
3bbf167
refactor(tauri): improve script execution for no-args case
goosewobbler Apr 9, 2026
87f1f94
test(electron, tauri): add comprehensive script execution tests
goosewobbler Apr 9, 2026
c81a43f
refactor(tauri): enhance script execution logic for no-args case
goosewobbler Apr 9, 2026
52d891f
refactor(tauri): enhance script execution for statement expressions
goosewobbler Apr 9, 2026
17c4255
refactor(tauri): embed command and arguments in script string for exe…
goosewobbler Apr 9, 2026
11b618c
refactor(tauri): pass command and arguments as function parameters in…
goosewobbler Apr 9, 2026
126659f
refactor(tauri): improve script wrapping logic for execution
goosewobbler Apr 9, 2026
90513e8
refactor(tauri): improve script execution handling for async results
goosewobbler Apr 9, 2026
fbf1381
refactor(tauri): enhance function detection in script execution
goosewobbler Apr 9, 2026
83e254a
refactor(tauri): enhance script execution for async compatibility
goosewobbler Apr 9, 2026
66ee9f2
refactor(tauri): enhance error handling in async script execution
goosewobbler Apr 9, 2026
725a83e
refactor(tauri): refine function detection logic in script execution
goosewobbler Apr 9, 2026
a1269f5
refactor(tauri): improve async script execution wrapping
goosewobbler Apr 9, 2026
aec6d24
refactor(tauri): improve return detection for pure expressions in scr…
goosewobbler Apr 9, 2026
1de3895
refactor(tauri): enhance async script execution wrapping for WebKit c…
goosewobbler Apr 9, 2026
ee5d38a
refactor(tauri): enhance error handling in async script execution
goosewobbler Apr 9, 2026
6b72060
refactor(tauri): streamline async script execution error handling
goosewobbler Apr 9, 2026
9182584
refactor(tauri): update script execution to use executeAsync for WebK…
goosewobbler Apr 9, 2026
60e09bd
refactor(tauri): improve pure expression detection in script execution
goosewobbler Apr 9, 2026
0d391e8
refactor(tauri): fix argument handling in async script execution
goosewobbler Apr 9, 2026
119b7b3
refactor(tauri): enhance pure expression detection in script execution
goosewobbler Apr 9, 2026
2cc06d6
refactor(tauri): expand pure expression detection in script execution
goosewobbler Apr 9, 2026
2de3568
refactor(tauri): enhance script execution logic for function and stat…
goosewobbler Apr 9, 2026
caca107
refactor(tauri): enhance function detection in script execution logic
goosewobbler Apr 9, 2026
9c76b98
refactor(tauri): improve async script execution for embedded provider
goosewobbler Apr 9, 2026
4976d20
refactor(tauri): improve function detection in script execution logic
goosewobbler Apr 9, 2026
70cfca5
refactor(tauri): simplify script execution for embedded provider
goosewobbler Apr 9, 2026
e562c4f
refactor(electron): enhance script execution handling in execute func…
goosewobbler Apr 9, 2026
2c9ca71
refactor(tauri): enhance arrow function detection in script execution
goosewobbler Apr 9, 2026
64a9684
refactor(electron): improve script statement detection in wrapStringS…
goosewobbler Apr 10, 2026
d0172ef
refactor(tauri): improve error handling for string scripts with argum…
goosewobbler Apr 10, 2026
e45001b
refactor(electron): refine arrow function detection in wrapStringScript
goosewobbler Apr 10, 2026
af003eb
refactor(tauri): ensure async handling in script execution
goosewobbler Apr 10, 2026
c718b0a
refactor(tauri): ensure async function handling in script execution
goosewobbler Apr 10, 2026
7979023
chore: reorder e2e scripts
goosewobbler Apr 10, 2026
648da6d
refactor(tauri): refine function detection in script execution
goosewobbler Apr 10, 2026
5a99329
refactor(electron): enhance script parsing for string inputs
goosewobbler Apr 10, 2026
6b91d62
refactor(tauri): simplify script handling in execute function
goosewobbler Apr 10, 2026
21b3c04
refactor(electron): improve statement keyword detection in wrapString…
goosewobbler Apr 10, 2026
f878857
refactor(tauri): enhance arrow function detection in script execution
goosewobbler Apr 10, 2026
612ae1c
test(electron): add tests for false positive handling in script execu…
goosewobbler Apr 10, 2026
21f14e0
refactor(tauri): clean up comments in execute function
goosewobbler Apr 10, 2026
1029e1f
refactor(tauri): enhance script wrapping logic in execute function
goosewobbler Apr 10, 2026
e8357d4
refactor(electron): improve string script handling in execute function
goosewobbler Apr 10, 2026
310e0a1
refactor(electron, tauri): improve escape sequence handling in execut…
goosewobbler Apr 10, 2026
e609d1f
refactor(tauri): streamline script evaluation in execute function
goosewobbler Apr 10, 2026
020f0bc
refactor(tauri): update script wrapping for expression evaluation
goosewobbler Apr 10, 2026
c7f89f7
refactor(electron): simplify async function wrapping in script execution
goosewobbler Apr 11, 2026
f493f8e
refactor(tauri): enhance script wrapping logic in execute function
goosewobbler Apr 11, 2026
e89c7dc
refactor(electron): optimize async function wrapping in script execution
goosewobbler Apr 11, 2026
d415750
refactor(tauri): implement semicolon detection outside quotes for scr…
goosewobbler Apr 11, 2026
8d71425
refactor(tauri): update script handling in TauriWorkerService
goosewobbler Apr 11, 2026
4a98230
refactor(tauri): enhance async function handling in script execution
goosewobbler Apr 11, 2026
8b1af1f
refactor(tauri): improve async handling for script execution in Tauri…
goosewobbler Apr 11, 2026
c2e16db
refactor(tauri): skip patching for internal executeWithinTauri calls
goosewobbler Apr 11, 2026
8b9f702
refactor(tauri): enhance error handling and improve async execution i…
goosewobbler Apr 11, 2026
fe105bb
refactor(tauri): update event emission to target app context
goosewobbler Apr 11, 2026
013a5e4
refactor(tauri): update event listener to target window context
goosewobbler Apr 11, 2026
e0356f9
refactor(tauri): enhance event handling in execute function
goosewobbler Apr 11, 2026
312c24e
chore: merge main into refactor/audit-string-interpolation
goosewobbler Apr 22, 2026
5a1f159
fix(tauri): break circular dependency between execute.ts and window.ts
goosewobbler Apr 22, 2026
e008495
test(tauri): update window.spec.ts to spy on pluginCache module
goosewobbler Apr 22, 2026
dbed72c
fix(electron): add word-boundary check for async/function in wrapStri…
goosewobbler Apr 22, 2026
9d3195a
fix(tauri-plugin): add word-boundary check for 'return' prefix in has…
goosewobbler Apr 22, 2026
152ea04
fix(electron): require => when paren-prefixed script is classified as…
goosewobbler Apr 22, 2026
3c14850
fix(electron): align executeCdp escape handling with execute.ts
goosewobbler Apr 22, 2026
7c41bfc
fix(tauri): route executeWithinTauri through executeAsync on non-embe…
goosewobbler Apr 23, 2026
727213f
fix(tauri): prepend return for expression-style string scripts on non…
goosewobbler Apr 23, 2026
2482568
fix(tauri-plugin): enhance script execution handling in guest-js
goosewobbler Apr 23, 2026
2bd885c
fix(tauri-service): add settleMs parameter to waitTestRunnerBackendReady
goosewobbler Apr 23, 2026
d93b308
fix(ci): enhance cleanup process for CrabNebula provider tests
goosewobbler Apr 23, 2026
a610b00
fix(tauri-service): improve function script handling for embedded Web…
goosewobbler Apr 23, 2026
4008cd7
fix(tauri-plugin): improve arrow function detection in script execution
goosewobbler Apr 23, 2026
d6f2ae2
feat(electron-service): add hasTopLevelArrow utility for improved scr…
goosewobbler Apr 23, 2026
0cffdd3
fix(tauri-plugin): enhance return detection for script execution
goosewobbler Apr 23, 2026
43053ef
fix(tauri-service): enhance backend process management and readiness …
goosewobbler Apr 23, 2026
5b5f26a
fix(tauri-service): improve port validation and process termination i…
goosewobbler Apr 23, 2026
3cacc77
fix(tauri-service): refactor process termination command in startTest…
goosewobbler Apr 23, 2026
b4c411e
fix(tauri-service): update script execution handling for embedded Web…
goosewobbler Apr 23, 2026
36f8964
refactor(electron-service): simplify IIFE wrapping for script execution
goosewobbler Apr 23, 2026
b0367f2
feat(electron-service): add hasSemicolonOutsideQuotes utility for scr…
goosewobbler Apr 23, 2026
3ed0a80
feat(tauri-plugin): add hasSemicolonOutsideQuotes utility for enhance…
goosewobbler Apr 23, 2026
57a8691
refactor(tauri-service): update script execution handling for embedde…
goosewobbler Apr 23, 2026
35efe7b
refactor(tauri-plugin): clarify script execution handling in Platform…
goosewobbler Apr 23, 2026
a004f59
refactor(tauri-service): update script handling for embedded WebDrive…
goosewobbler Apr 23, 2026
2cb6d81
refactor(tauri-service): simplify IIFE structure in mock script execu…
goosewobbler Apr 23, 2026
329ca84
refactor(tauri-service): update script structure for WebDriver compat…
goosewobbler Apr 23, 2026
5d0968b
refactor: move script detection utilities to native-utils
goosewobbler Apr 23, 2026
fc4f722
test(native-utils): add unit tests for script detection utilities
goosewobbler Apr 23, 2026
4ccdd4b
refactor(tauri-service): improve stdout logging and enhance backend r…
goosewobbler Apr 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 0 additions & 177 deletions docs/tauri-playwright-analysis.md

This file was deleted.

16 changes: 8 additions & 8 deletions docs/tauri-playwright-improvements-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

## Improvement Summary

| # | Improvement | Applies To | Effort | Impact |
|---|-------------|------------|--------|--------|
| 1 | Browser-only test mode with mocked native IPC | Tauri + Electron | Large | High |
| 2 | Direct WebView eval channel (supplement WebDriver) | Tauri (embedded) | Large | High |
| 3 | Multi-window label configuration | Tauri | Small | Medium |
| 4 | Native screenshot capture | Tauri + Electron | Medium | Low |
| 5 | Audit JS string interpolation / escaping | Tauri + Electron | Small | Medium |
| 6 | IPC mock serialization pattern | Tauri + Electron | Medium | Medium |
| # | Improvement | Applies To | Effort | Impact | Status |
|---|-------------|------------|--------|--------|--------|
| 1 | Browser-only test mode with mocked native IPC | Tauri + Electron | Large | High | Pending |
| 2 | Direct WebView eval channel (supplement WebDriver) | Tauri (embedded) | Large | High | Pending |
| 3 | Multi-window label configuration | Tauri | Small | Medium | Pending |
| 4 | Native screenshot capture | Tauri + Electron | Medium | Low | Pending |
| 5 | Audit JS string interpolation / escaping | Tauri + Electron | Small | Medium | **Done** |
| 6 | IPC mock serialization pattern | Tauri + Electron | Medium | Medium | Pending |

---

Expand Down
4 changes: 3 additions & 1 deletion packages/electron-service/src/commands/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ export async function execute<ReturnValue, InnerArguments extends unknown[]>(
throw new Error('WDIO browser is not yet initialised');
}

const scriptString = typeof script === 'function' ? script.toString() : script;

const returnValue = await browser.execute(
function executeWithinElectron(script: string, ...args) {
return window.wdioElectron.execute(script, args);
},
`${script}`,
scriptString,
...args,
);

Expand Down
30 changes: 30 additions & 0 deletions packages/electron-service/test/commands/execute.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,34 @@ describe('execute Command', () => {
expect(globalThis.browser.execute).toHaveBeenCalledWith(expect.any(Function), '() => 1 + 2 + 3');
expect(globalThis.wdioElectron.execute).toHaveBeenCalledWith('() => 1 + 2 + 3', []);
});

it('should handle scripts with quotes', async () => {
const scriptWithQuotes = '() => "He said \\"hello\\""';
await execute(globalThis.browser, scriptWithQuotes);
expect(globalThis.browser.execute).toHaveBeenCalledWith(expect.any(Function), scriptWithQuotes);
});

it('should handle scripts with newlines', async () => {
const scriptWithNewlines = '() => "line1\\nline2"';
await execute(globalThis.browser, scriptWithNewlines);
expect(globalThis.browser.execute).toHaveBeenCalledWith(expect.any(Function), scriptWithNewlines);
});

it('should handle scripts with unicode', async () => {
const scriptWithUnicode = '() => "Hello 世界"';
await execute(globalThis.browser, scriptWithUnicode);
expect(globalThis.browser.execute).toHaveBeenCalledWith(expect.any(Function), scriptWithUnicode);
});

it('should handle scripts with backslashes', async () => {
const scriptWithBackslashes = '() => "C:\\\\path\\\\file"';
await execute(globalThis.browser, scriptWithBackslashes);
expect(globalThis.browser.execute).toHaveBeenCalledWith(expect.any(Function), scriptWithBackslashes);
});

it('should handle mixed special characters', async () => {
const script = '() => "Test \\n \\t \\u001b and \\\\ backslash"';
await execute(globalThis.browser, script);
expect(globalThis.browser.execute).toHaveBeenCalledWith(expect.any(Function), script);
});
});
17 changes: 14 additions & 3 deletions packages/tauri-plugin/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,17 @@ pub(crate) async fn execute<R: Runtime>(
let tx = Arc::new(Mutex::new(Some(tx)));

// Build the script with args if offered
// For args: inject Tauri APIs as first param, then pass user args
// For no-args: preserve the script expression and evaluate it below
let script = if !request.args.is_empty() {
let args_json = serde_json::to_string(&request.args)
.map_err(|e| crate::Error::SerializationError(format!("Failed to serialize args: {}", e)))?;
format!("(function() {{ const __wdio_args = {}; return ({}); }})()", args_json, request.script)
format!(
"(function() {{ const __wdio_fn = ({}); const __wdio_args = {}; return __wdio_fn({{ core: window.__TAURI__?.core, event: window.__TAURI__?.event, log: window.__TAURI__?.log }}, ...__wdio_args); }})()",
request.script, args_json
)
Comment thread
goosewobbler marked this conversation as resolved.
Outdated
} else {
// No args - preserve the script expression and evaluate it below
request.script.clone()
};
Comment thread
goosewobbler marked this conversation as resolved.

Expand Down Expand Up @@ -122,8 +128,13 @@ pub(crate) async fn execute<R: Runtime>(
throw new Error('window.__TAURI__.core.invoke not available after timeout');
}}

// Execute the user's script
const result = await ({});
// Execute the user's script.
// If expression resolves to a function, call it with Tauri APIs.
// Otherwise, await the value directly.
const __wdio_script = ({});
const result = typeof __wdio_script === 'function'
? await __wdio_script({{ core: window.__TAURI__?.core, event: window.__TAURI__?.event }})
: await __wdio_script;
Comment thread
goosewobbler marked this conversation as resolved.
Outdated

// Emit the result using the current window's event emitter
// This ensures the event goes to the same window where we're listening
Expand Down
36 changes: 21 additions & 15 deletions packages/tauri-service/src/commands/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ export async function execute<ReturnValue, InnerArguments extends unknown[]>(
log.debug('Plugin availability cached, skipping check');
}

// Convert function to string - keep parameters intact, plugin will inject tauri as first arg
// Convert function to string - keep parameters intact, plugin will handle escaping
// For functions: use .toString() (produces valid JS function source)
// For strings: send as-is (Rust handles proper escaping when args present)
const scriptString = typeof script === 'function' ? script.toString() : script;

// Execute via plugin's execute command with better error handling
Expand Down Expand Up @@ -111,21 +113,25 @@ export async function execute<ReturnValue, InnerArguments extends unknown[]>(
);

// Extract result or error from wrapped response
try {
if (result && typeof result === 'string') {
const parsed = JSON.parse(result) as { __wdio_error__?: string; __wdio_value__?: unknown };
if (parsed.__wdio_error__) {
throw new Error(parsed.__wdio_error__);
}
if (parsed.__wdio_value__ !== undefined) {
log.debug(`Execute result:`, parsed.__wdio_value__);
return parsed.__wdio_value__ as ReturnValue;
}
let parsed: { __wdio_error__?: string; __wdio_value__?: unknown } | undefined;
if (result && typeof result === 'string') {
try {
parsed = JSON.parse(result) as { __wdio_error__?: string; __wdio_value__?: unknown };
} catch (parseError) {
throw new Error(
`Failed to parse execute result: ${parseError instanceof Error ? parseError.message : String(parseError)}, raw result: ${result}`,
);
}
} catch (parseError) {
throw new Error(
`Failed to parse execute result: ${parseError instanceof Error ? parseError.message : String(parseError)}, raw result: ${result}`,
);
}

// Check for script errors AFTER parsing (outside try/catch to avoid re-wrapping)
if (parsed?.__wdio_error__) {
throw new Error(parsed.__wdio_error__);
}

if (parsed?.__wdio_value__ !== undefined) {
log.debug(`Execute result:`, parsed.__wdio_value__);
return parsed.__wdio_value__ as ReturnValue;
}

log.debug(`Execute result:`, result);
Expand Down
Loading
Loading