Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
156 changes: 156 additions & 0 deletions .github/workflows/tests_webview_simulator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
name: "tests WebView (iOS Simulator)"

on:
# pull_request trigger disabled to avoid CI churn during wk_wv iteration - restore before merge

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

env:
FORCE_COLOR: 1
ELECTRON_SKIP_BINARY_DOWNLOAD: 1

jobs:
test_webview_simulator:
name: "WebView on iOS Simulator (${{ matrix.shard }}/4)"
runs-on: macos-15
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4]
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Runner environment
run: |
echo "::group::OS / Xcode"
sw_vers
uname -a
xcode-select -p
xcodebuild -version
echo "::endgroup::"
echo "::group::Available iOS runtimes"
xcrun simctl list runtimes
echo "::endgroup::"
echo "::group::Available device types"
xcrun simctl list devicetypes | grep -i 'iPhone\|iPad' | head -40
echo "::endgroup::"
echo "::group::Network config"
cat /etc/hosts
ifconfig lo0
echo "::endgroup::"

- name: Ensure ::1 localhost in /etc/hosts
run: |
if grep -qE '^::1[[:space:]]+localhost' /etc/hosts; then
echo "::1 localhost already present"
else
echo "::1 localhost" | sudo tee -a /etc/hosts
echo "Added ::1 localhost"
fi
echo "--- /etc/hosts after ---"
cat /etc/hosts

- name: npm ci
run: |
echo "::group::npm ci"
npm ci
echo "::endgroup::"

- name: npm run build
run: |
echo "::group::npm run build"
npm run build
echo "::endgroup::"

- name: Install ios-webkit-debug-proxy
run: |
echo "::group::brew install ios-webkit-debug-proxy"
brew install ios-webkit-debug-proxy
which ios_webkit_debug_proxy
ios_webkit_debug_proxy --help 2>&1 | head -40 || true
echo "::endgroup::"

- name: Boot iOS Simulator
uses: futureware-tech/simulator-action@v5
with:
# Per wiki/Devices-macos-15.md only iPhone 16/17 series ship pre-installed; iPhone 15 isn't.
model: 'iPhone 16'
os_version: '18.6'
wait_for_boot: true
boot_timeout_seconds: 300

- name: Simulator state after boot
run: |
echo "::group::Booted devices"
xcrun simctl list devices booted
echo "::endgroup::"
echo "::group::Simulator processes"
pgrep -lf Simulator || true
pgrep -lf launchd_sim || true
echo "::endgroup::"

- name: Locate simulator webinspectord socket
run: |
echo "::group::Locating com.apple.webinspectord_sim.socket"
# On modern macOS, ios_webkit_debug_proxy can no longer auto-discover the simulator;
# we have to point -s at the launchd-owned unix socket.
for i in $(seq 1 15); do
SOCK=$(lsof -aUc launchd_sim 2>/dev/null | awk '/com\.apple\.webinspectord_sim\.socket/{print $NF; exit}')
[[ -n "$SOCK" ]] && break
echo "attempt $i: socket not found yet"
sleep 1
done
if [[ -z "$SOCK" ]]; then
echo "Failed to locate webinspectord_sim.socket"
echo "--- launchd_sim file table ---"
lsof -aUc launchd_sim 2>/dev/null || true
exit 1
fi
echo "socket: $SOCK"
echo "SIM_WI_SOCKET=unix:$SOCK" >> $GITHUB_ENV
echo "::endgroup::"

- name: Start ios-webkit-debug-proxy
run: |
echo "::group::Starting proxy (SIM_WI_SOCKET=$SIM_WI_SOCKET)"
ios_webkit_debug_proxy -F -d -s "$SIM_WI_SOCKET" -c "null:9221,:9222-9322" > "$RUNNER_TEMP/iwdp.log" 2>&1 &
PID=$!
echo "IWDP_PID=$PID" >> $GITHUB_ENV
echo "proxy pid=$PID"
sleep 3
if ! kill -0 "$PID" 2>/dev/null; then
echo "Proxy died immediately. Log:"
cat "$RUNNER_TEMP/iwdp.log"
exit 1
fi
echo "::endgroup::"
echo "::group::Listening ports"
lsof -nP -iTCP -sTCP:LISTEN | grep -E "9221|9222|ios_webkit" || true
echo "::endgroup::"

- name: Run WebView tests
run: |
echo "::group::Test run (shard ${{ matrix.shard }}/4)"
npx playwright test --config tests/webview/playwright.config.ts --shard=${{ matrix.shard }}/4
echo "::endgroup::"

- name: Stop proxy
if: always()
run: |
[[ -n "$IWDP_PID" ]] && kill "$IWDP_PID" 2>/dev/null || true
# Simulator shutdown is owned by futureware-tech/simulator-action's post step.

- name: Upload artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: webview-simulator-logs-${{ matrix.shard }}
path: |
${{ github.workspace }}/test-results/**
if-no-files-found: ignore
22 changes: 11 additions & 11 deletions docs/src/api/class-frame.md
Original file line number Diff line number Diff line change
Expand Up @@ -680,33 +680,33 @@ Console.WriteLine(await frame.EvaluateAsync<int>("1 + 2")); // prints "3"
[ElementHandle] instances can be passed as an argument to the [`method: Frame.evaluate`]:

```js
const bodyHandle = await frame.evaluate('document.body');
const bodyHandle = await frame.evaluateHandle('document.body');
const html = await frame.evaluate(([body, suffix]) =>
body.innerHTML + suffix, [bodyHandle, 'hello'],
);
await bodyHandle.dispose();
```

```java
ElementHandle bodyHandle = frame.evaluate("document.body");
ElementHandle bodyHandle = frame.evaluateHandle("document.body");
String html = (String) frame.evaluate("([body, suffix]) => body.innerHTML + suffix", Arrays.asList(bodyHandle, "hello"));
bodyHandle.dispose();
```

```python async
body_handle = await frame.evaluate("document.body")
body_handle = await frame.evaluate_handle("document.body")
html = await frame.evaluate("([body, suffix]) => body.innerHTML + suffix", [body_handle, "hello"])
await body_handle.dispose()
```

```python sync
body_handle = frame.evaluate("document.body")
body_handle = frame.evaluate_handle("document.body")
html = frame.evaluate("([body, suffix]) => body.innerHTML + suffix", [body_handle, "hello"])
body_handle.dispose()
```

```csharp
var bodyHandle = await frame.EvaluateAsync("document.body");
var bodyHandle = await frame.EvaluateHandleAsync("document.body");
var html = await frame.EvaluateAsync<string>("([body, suffix]) => body.innerHTML + suffix", new object [] { bodyHandle, "hello" });
await bodyHandle.DisposeAsync();
```
Expand Down Expand Up @@ -773,11 +773,11 @@ JSHandle aHandle = frame.evaluateHandle("document"); // Handle for the "document
```

```python async
a_handle = await page.evaluate_handle("document") # handle for the "document"
a_handle = await frame.evaluate_handle("document") # handle for the "document"
```

```python sync
a_handle = page.evaluate_handle("document") # handle for the "document"
a_handle = frame.evaluate_handle("document") # handle for the "document"
```

```csharp
Expand All @@ -803,15 +803,15 @@ resultHandle.dispose();
```

```python async
a_handle = await page.evaluate_handle("document.body")
result_handle = await page.evaluate_handle("body => body.innerHTML", a_handle)
a_handle = await frame.evaluate_handle("document.body")
result_handle = await frame.evaluate_handle("body => body.innerHTML", a_handle)
print(await result_handle.json_value())
await result_handle.dispose()
```

```python sync
a_handle = page.evaluate_handle("document.body")
result_handle = page.evaluate_handle("body => body.innerHTML", a_handle)
a_handle = frame.evaluate_handle("document.body")
result_handle = frame.evaluate_handle("body => body.innerHTML", a_handle)
print(result_handle.json_value())
result_handle.dispose()
```
Expand Down
10 changes: 5 additions & 5 deletions docs/src/api/class-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -1522,33 +1522,33 @@ Console.WriteLine(await page.EvaluateAsync<int>("1 + 2")); // prints "3"
[ElementHandle] instances can be passed as an argument to the [`method: Page.evaluate`]:

```js
const bodyHandle = await page.evaluate('document.body');
const bodyHandle = await page.evaluateHandle('document.body');
const html = await page.evaluate<string, HTMLElement>(([body, suffix]) =>
body.innerHTML + suffix, [bodyHandle, 'hello']
);
await bodyHandle.dispose();
```

```java
ElementHandle bodyHandle = page.evaluate("document.body");
ElementHandle bodyHandle = page.evaluateHandle("document.body");
String html = (String) page.evaluate("([body, suffix]) => body.innerHTML + suffix", Arrays.asList(bodyHandle, "hello"));
bodyHandle.dispose();
```

```python async
body_handle = await page.evaluate("document.body")
body_handle = await page.evaluate_handle("document.body")
html = await page.evaluate("([body, suffix]) => body.innerHTML + suffix", [body_handle, "hello"])
await body_handle.dispose()
```

```python sync
body_handle = page.evaluate("document.body")
body_handle = page.evaluate_handle("document.body")
html = page.evaluate("([body, suffix]) => body.innerHTML + suffix", [body_handle, "hello"])
body_handle.dispose()
```

```csharp
var bodyHandle = await page.EvaluateAsync("document.body");
var bodyHandle = await page.EvaluateHandleAsync("document.body");
var html = await page.EvaluateAsync<string>("([body, suffix]) => body.innerHTML + suffix", new object [] { bodyHandle, "hello" });
await bodyHandle.DisposeAsync();
```
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"ctest": "playwright test --config=tests/library/playwright.config.ts --project=chromium-*",
"ftest": "playwright test --config=tests/library/playwright.config.ts --project=firefox-*",
"wtest": "playwright test --config=tests/library/playwright.config.ts --project=webkit-*",
"wvtest": "playwright test --config=tests/webview/playwright.config.ts",
"atest": "playwright test --config=tests/android/playwright.config.ts",
"etest": "playwright test --config=tests/electron/playwright.config.ts",
"itest": "playwright test --config=tests/installation/playwright.config.ts",
Expand Down
5 changes: 3 additions & 2 deletions packages/injected/src/injectedScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1112,8 +1112,9 @@ export class InjectedScript {
return;

// Playwright only issues trusted events, so allow any custom events originating from
// the page or content scripts.
if (!event.isTrusted)
// the page or content scripts. The WebView backend cannot produce trusted events, so
// it marks synthetic events with __pwTrustedSynthetic to opt back into interception.
if (!event.isTrusted && !(event as any).__pwTrustedSynthetic)
return;

// Determine the event point. Note that Firefox does not always have window.TouchEvent.
Expand Down
8 changes: 4 additions & 4 deletions packages/playwright-client/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export interface Page {
* [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate):
*
* ```js
* const bodyHandle = await page.evaluate('document.body');
* const bodyHandle = await page.evaluateHandle('document.body');
* const html = await page.evaluate<string, HTMLElement>(([body, suffix]) =>
* body.innerHTML + suffix, [bodyHandle, 'hello']
* );
Expand Down Expand Up @@ -172,7 +172,7 @@ export interface Page {
* [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#page-evaluate):
*
* ```js
* const bodyHandle = await page.evaluate('document.body');
* const bodyHandle = await page.evaluateHandle('document.body');
* const html = await page.evaluate<string, HTMLElement>(([body, suffix]) =>
* body.innerHTML + suffix, [bodyHandle, 'hello']
* );
Expand Down Expand Up @@ -5372,7 +5372,7 @@ export interface Frame {
* [frame.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frame-evaluate):
*
* ```js
* const bodyHandle = await frame.evaluate('document.body');
* const bodyHandle = await frame.evaluateHandle('document.body');
* const html = await frame.evaluate(([body, suffix]) =>
* body.innerHTML + suffix, [bodyHandle, 'hello'],
* );
Expand Down Expand Up @@ -5419,7 +5419,7 @@ export interface Frame {
* [frame.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frame-evaluate):
*
* ```js
* const bodyHandle = await frame.evaluate('document.body');
* const bodyHandle = await frame.evaluateHandle('document.body');
* const html = await frame.evaluate(([body, suffix]) =>
* body.innerHTML + suffix, [bodyHandle, 'hello'],
* );
Expand Down
6 changes: 4 additions & 2 deletions packages/playwright-core/src/client/browserType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
}

async _connectOverCDP(endpointURL: string, params: api.ConnectOverCDPOptions = {}): Promise<Browser> {
if (this.name() !== 'chromium')
throw new Error('Connecting over CDP is only supported in Chromium.');
if (this.name() !== 'chromium' && this.name() !== 'webkit')
throw new Error('Connecting over CDP is only supported in Chromium and WebKit.');
const headers = params.headers ? headersObjectToArray(params.headers) : undefined;
const result = await this._channel.connectOverCDP({
endpointURL,
Expand All @@ -168,6 +168,8 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
async _connectOverCDPTransport(transport: api.ConnectionTransport): Promise<Browser> {
if (this.name() !== 'chromium')
throw new Error('Connecting over CDP is only supported in Chromium.');
if (this._connection.isRemote())
throw new Error('Passing a ConnectionTransport to connectOverCDP is not supported when connecting remotely.');
const result = await this._channel.connectOverCDPTransport({ transport: transport as any });
return await this._browserFromConnectResult(result);
}
Expand Down
10 changes: 10 additions & 0 deletions packages/playwright-core/src/server/webkit/DEPS.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[*]
@isomorphic/**
@utils/**
../
../registry/
node_modules/jpeg-js
node_modules/pngjs

[webkit.ts]
./webview/wvBrowser.ts
9 changes: 8 additions & 1 deletion packages/playwright-core/src/server/webkit/webkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ import path from 'path';
import { wrapInASCIIBox } from '@utils/ascii';
import { spawnAsync } from '@utils/spawnAsync';
import { kBrowserCloseMessageId } from './wkConnection';
import { Browser } from '../browser';
import { BrowserType, kNoXServerRunningError } from '../browserType';
import { WKBrowser } from '../webkit/wkBrowser';
import { WKBrowser } from './wkBrowser';
import { connectOverRDP } from './webview/wvBrowser';

import type { BrowserOptions } from '../browser';
import type { SdkObject } from '../instrumentation';
import type { Progress } from '../progress';
import type { ConnectionTransport } from '../transport';
import type * as types from '../types';

Expand All @@ -37,6 +40,10 @@ export class WebKit extends BrowserType {
return WKBrowser.connect(this.attribution.playwright, transport, options);
}

override async connectOverCDP(progress: Progress, endpointURL: string, options: { slowMo?: number, headers?: types.HeadersArray, isLocal?: boolean, noDefaults?: boolean }): Promise<Browser> {
return connectOverRDP(progress, this, endpointURL, options);
}

override amendEnvironment(env: NodeJS.ProcessEnv, userDataDir: string, isPersistent: boolean, options: types.LaunchOptions): NodeJS.ProcessEnv {
return {
...env,
Expand Down
Loading
Loading