Lightpanda: the headless browser designed for AI and automation
enable cors by default
Pierre Tachoire12d3880d2088
diff --git a/.github/workflows/e2e-integration-test.yml b/.github/workflows/e2e-integration-test.ymlindex 8999ce2ee..5a52a23cd 100644--- a/.github/workflows/e2e-integration-test.yml+++ b/.github/workflows/e2e-integration-test.yml@@ -69,7 +69,7 @@ jobs:- name: run end to end integration testscontinue-on-error: truerun: |- ./lightpanda serve --experimental-features cors --http-cache-dir /tmp/lp-cache --http-proxy ${{ secrets.MASSIVE_PROXY_RESIDENTIAL_US }} --log-level error & echo $! > LPD.pid+ ./lightpanda serve --http-cache-dir /tmp/lp-cache --http-proxy ${{ secrets.MASSIVE_PROXY_RESIDENTIAL_US }} --log-level error & echo $! > LPD.pidgo run integration/main.go |tee result.logkill `cat LPD.pid`diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.ymlindex f0c3f1810..9c06217a1 100644--- a/.github/workflows/e2e-test.yml+++ b/.github/workflows/e2e-test.yml@@ -117,7 +117,7 @@ jobs:echo "value=$args" >> "$GITHUB_OUTPUT"- run: |- ./lightpanda serve --experimental-features cors --port 9222 ${{ steps.args.outputs.value }} &+ ./lightpanda serve --port 9222 ${{ steps.args.outputs.value }} &- run: |go run runner/main.go@@ -163,7 +163,7 @@ jobs:- id: argsname: build LP argsrun: |- args="--experimental-features cors --http-cache-dir /tmp/lp-cache --load-resources worker --load-resources iframe"+ args="--http-cache-dir /tmp/lp-cache --load-resources worker --load-resources iframe"args="$args --protocol cdp --protocol webdriver"[ "${{ matrix.robotstxt }}" = "true" ] && args="$args --obey-robots"[ "${{ matrix.wba }}" = "true" ] && args="$args --web-bot-auth-key-file private_key.pem"@@ -227,7 +227,6 @@ jobs:exec 3<<< "${{ secrets.WBA_PRIVATE_KEY_PEM }}"./lightpanda fetch --dump http://127.0.0.1:8989/ \- --experimental-features cors \--web-bot-auth-key-file /proc/self/fd/3 \--web-bot-auth-keyid ${{ vars.WBA_KEY_ID }} \--web-bot-auth-domain ${{ vars.WBA_DOMAIN }}@@ -251,7 +250,6 @@ jobs:exec 3<<< "${{ secrets.WBA_PRIVATE_KEY_PEM }}"./lightpanda fetch --dump "http://127.0.0.1:8989/redirect?to=http://127.0.0.1:8990/" \- --experimental-features cors \--web-bot-auth-key-file /proc/self/fd/3 \--web-bot-auth-keyid ${{ vars.WBA_KEY_ID }} \--web-bot-auth-domain ${{ vars.WBA_DOMAIN }}@@ -430,7 +428,7 @@ jobs:- run: chmod a+x ./lightpanda- - run: ./lightpanda fetch --experimental-features cors "https://demo-browser.lightpanda.io/campfire-commerce/"+ - run: ./lightpanda fetch "https://demo-browser.lightpanda.io/campfire-commerce/"agent-deterministic:name: agent deterministic replay@@ -483,7 +481,7 @@ jobs:jq --version- timeout 30 ./lightpanda mcp --experimental-features cors > mcp.out <<'JSONRPC'+ timeout 30 ./lightpanda mcp > mcp.out <<'JSONRPC'{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"ci","version":"1.0.0"}}}{"jsonrpc":"2.0","method":"notifications/initialized"}{"jsonrpc":"2.0","id":2,"method":"tools/list"}diff --git a/README.md b/README.mdindex b315d50db..b7756a825 100644--- a/README.md+++ b/README.md@@ -258,7 +258,7 @@ Set `LIGHTPANDA_DISABLE_CORE_DUMP` (to any value) to suppress crash core dumps bHere are the key features we have implemented.For full details, see our [Web Platform Tests results](https://perf.lightpanda.io/wpt).-- [x] CORS (enable with `--experimental-features cors`)+- [x] CORS- [x] HTTP loader ([Libcurl](https://curl.se/libcurl/))- [x] HTML parser ([html5ever](https://github.com/servo/html5ever))- [x] DOM treediff --git a/src/Config.zig b/src/Config.zigindex e6b16d37e..556baf9f0 100644--- a/src/Config.zig+++ b/src/Config.zig@@ -239,7 +239,7 @@ pub const LoadResources = packed struct(u4) {};pub const ExperimentalFeatures = packed struct(u2) {- cors: bool = false,+ cors: bool = false, // ignored, kept only for backward compatibility.serviceworker: bool = false,};@@ -248,6 +248,7 @@ const CommonOptions = .{.{ .name = "obey_robots", .type = bool },.{ .name = "robot_store_entry_limit", .type = ?u32, .default = 1000 },.{ .name = "cors_store_entry_limit", .type = ?u32, .default = 1000 },+ .{ .name = "disable_cors", .type = bool, .default = false },.{ .name = "proxy_bearer_token", .type = ?[:0]const u8 },.{ .name = "http_proxy", .type = ?[:0]const u8 },.{ .name = "http_max_concurrent", .type = ?u8 },@@ -552,6 +553,13 @@ pub fn tlsVerifyHost(self: *const Config) bool {};}+pub fn obeyCors(self: *const Config) bool {+ return switch (self.mode) {+ inline .serve, .fetch, .mcp, .agent => |opts| opts.disable_cors == false,+ else => unreachable,+ };+}+pub fn obeyRobots(self: *const Config) bool {return switch (self.mode) {inline .serve, .fetch, .mcp, .agent => |opts| opts.obey_robots,diff --git a/src/cli.zig b/src/cli.zigindex 881644427..47d0414c2 100644--- a/src/cli.zig+++ b/src/cli.zig@@ -766,6 +766,8 @@ pub fn Builder(comptime commands: anytype) type {break :blk command.options;};+ // toKebabCase walks every byte of every name.+ @setEvalBranchQuota(50_000);iter_args: while (args.next()) |option_name| {inline for (options) |option| {const name = option.name;diff --git a/src/help.zon b/src/help.zonindex 91f19b734..bbb000d08 100644--- a/src/help.zon+++ b/src/help.zon@@ -409,14 +409,13 @@\\ --cors-store-entry-limit <INT>\\ Maximum number of entries kept in the CorsStore. 0 means no limit.\\ Defaults to 1000.+ \\ --disable-cors+ \\ Skip CORS checks on fetch/XHR requests.+ \\ Defaults to false.\\ --experimental-features <FEATURE>\\ Enable an experimental, unstable feature. Can be passed multiple times.\\ Behavior may change or be removed without notice.\\ Defaults to none enabled.- \\ Allowed values:- \\ cors Obey CORS (cross-origin resource sharing) checks- \\ on fetch/XHR requests instead of allowing them- \\ unconditionally.\\ --load-resources <RESOURCE>\\ Sub-resource to actually request. Can be passed multiple times.\\ Defaults to requesting none of them.diff --git a/src/network/HttpClient.zig b/src/network/HttpClient.zigindex decf406a4..0ba5cd4ae 100644--- a/src/network/HttpClient.zig+++ b/src/network/HttpClient.zig@@ -244,7 +244,7 @@ pub fn init(self: *Client, app: *lp.App) !void {.serve_mode = config.mode == .serve,.obey_robots = config.obeyRobots(),.http_version = config.httpVersion(),- .obey_cors = config.experimentalFeatures().cors,+ .obey_cors = config.obeyCors(),.robots = .{.network = network,.single_flight = .init(allocator),