Skip to content

Lightpanda: the headless browser designed for AI and automation

Fix: Allow EventSource with relative URLs

Karl Seguin8ec64547e7b5
diff --git a/src/browser/tests/net/eventsource.html b/src/browser/tests/net/eventsource.html
index ce2855a89..99e90950f 100644
--- a/src/browser/tests/net/eventsource.html
+++ b/src/browser/tests/net/eventsource.html
@@ -49,6 +49,23 @@
}
</script>
+<script id=relative_url type=module>
+{
+ const state = await testing.async();
+ const es = new EventSource('/sse/simple');
+ testing.expectEqual('http://127.0.0.1:9582/sse/simple', es.url);
+ es.onerror = () => { throw new Error('unexpected error'); };
+ es.onmessage = (e) => {
+ es.close();
+ state.resolve(e.data);
+ };
+
+ await state.done((data) => {
+ testing.expectEqual('first', data);
+ });
+}
+</script>
+
<script id=streaming type=module>
{
// The server only sends "second" after seeing our /sse/flag request, which
diff --git a/src/browser/webapi/net/EventSource.zig b/src/browser/webapi/net/EventSource.zig
index 546e2c20e..9f3a42b75 100644
--- a/src/browser/webapi/net/EventSource.zig
+++ b/src/browser/webapi/net/EventSource.zig
@@ -116,7 +116,7 @@ pub fn init(url: []const u8, opts_: ?Opts, exec: *const Execution) !*EventSource
log.debug(.http, "EventSource connecting", .{ .url = resolved });
}
- if (std.ascii.startsWithIgnoreCase(url, "http://") == false and std.ascii.startsWithIgnoreCase(url, "https://") == false) {
+ if (std.ascii.startsWithIgnoreCase(resolved, "http://") == false and std.ascii.startsWithIgnoreCase(resolved, "https://") == false) {
try self.scheduleTask(failConnection, 0, "EventSource.fail");
return self;
}