mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-16 00:08:59 +00:00
Error on null page/scope
This commit is contained in:
@@ -377,7 +377,7 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
|||||||
|
|
||||||
self.isolated_world = .{
|
self.isolated_world = .{
|
||||||
.name = try self.arena.dupe(u8, world_name),
|
.name = try self.arena.dupe(u8, world_name),
|
||||||
.scope = undefined,
|
.scope = null,
|
||||||
.executor = executor,
|
.executor = executor,
|
||||||
.grant_universal_access = grant_universal_access,
|
.grant_universal_access = grant_universal_access,
|
||||||
};
|
};
|
||||||
@@ -519,7 +519,8 @@ const IsolatedWorld = struct {
|
|||||||
self.executor.deinit();
|
self.executor.deinit();
|
||||||
self.scope = null;
|
self.scope = null;
|
||||||
}
|
}
|
||||||
pub fn removeContext(self: *IsolatedWorld) void {
|
pub fn removeContext(self: *IsolatedWorld) !void {
|
||||||
|
if (self.scope == null) return error.NoIsolatedContextToRemove;
|
||||||
self.executor.endScope();
|
self.executor.endScope();
|
||||||
self.scope = null;
|
self.scope = null;
|
||||||
}
|
}
|
||||||
@@ -530,6 +531,7 @@ const IsolatedWorld = struct {
|
|||||||
// This also means this pointer becomes invalid after removePage untill a new page is created.
|
// This also means this pointer becomes invalid after removePage untill a new page is created.
|
||||||
// Currently we have only 1 page/frame and thus also only 1 state in the isolate world.
|
// Currently we have only 1 page/frame and thus also only 1 state in the isolate world.
|
||||||
pub fn createContext(self: *IsolatedWorld, page: *Page) !void {
|
pub fn createContext(self: *IsolatedWorld, page: *Page) !void {
|
||||||
|
if (self.scope != null) return error.Only1IsolatedContextSupported;
|
||||||
self.scope = try self.executor.startScope(&page.window, &page.state, {}, false);
|
self.scope = try self.executor.startScope(&page.window, &page.state, {}, false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ fn createIsolatedWorld(cmd: anytype) !void {
|
|||||||
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
|
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
|
||||||
|
|
||||||
const world = try bc.createIsolatedWorld(params.worldName, params.grantUniveralAccess);
|
const world = try bc.createIsolatedWorld(params.worldName, params.grantUniveralAccess);
|
||||||
const page = bc.session.currentPage().?;
|
const page = bc.session.currentPage() orelse return error.PageNotLoaded;
|
||||||
try pageCreated(bc, page);
|
try pageCreated(bc, page);
|
||||||
const scope = world.scope.?;
|
const scope = world.scope.?;
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ fn navigate(cmd: anytype) !void {
|
|||||||
|
|
||||||
const url = try URL.parse(params.url, "https");
|
const url = try URL.parse(params.url, "https");
|
||||||
|
|
||||||
var page = bc.session.currentPage().?;
|
var page = bc.session.currentPage() orelse return error.PageNotLoaded;
|
||||||
bc.loader_id = bc.cdp.loader_id_gen.next();
|
bc.loader_id = bc.cdp.loader_id_gen.next();
|
||||||
try cmd.sendResult(.{
|
try cmd.sendResult(.{
|
||||||
.frameId = target_id,
|
.frameId = target_id,
|
||||||
@@ -223,7 +223,7 @@ pub fn pageNavigate(bc: anytype, event: *const Notification.PageNavigate) !void
|
|||||||
var buffer: [512]u8 = undefined;
|
var buffer: [512]u8 = undefined;
|
||||||
{
|
{
|
||||||
var fba = std.heap.FixedBufferAllocator.init(&buffer);
|
var fba = std.heap.FixedBufferAllocator.init(&buffer);
|
||||||
const page = bc.session.currentPage().?;
|
const page = bc.session.currentPage() orelse return error.PageNotLoaded;
|
||||||
const aux_data = try std.fmt.allocPrint(fba.allocator(), "{{\"isDefault\":true,\"type\":\"default\",\"frameId\":\"{s}\"}}", .{target_id});
|
const aux_data = try std.fmt.allocPrint(fba.allocator(), "{{\"isDefault\":true,\"type\":\"default\",\"frameId\":\"{s}\"}}", .{target_id});
|
||||||
bc.inspector.contextCreated(
|
bc.inspector.contextCreated(
|
||||||
page.scope,
|
page.scope,
|
||||||
@@ -249,7 +249,7 @@ pub fn pageNavigate(bc: anytype, event: *const Notification.PageNavigate) !void
|
|||||||
pub fn pageRemove(bc: anytype) !void {
|
pub fn pageRemove(bc: anytype) !void {
|
||||||
// The main page is going to be removed, we need to remove contexts from other worlds first.
|
// The main page is going to be removed, we need to remove contexts from other worlds first.
|
||||||
if (bc.isolated_world) |*isolated_world| {
|
if (bc.isolated_world) |*isolated_world| {
|
||||||
isolated_world.removeContext();
|
try isolated_world.removeContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user