Finding the ID of the default BrowserContext

26 views
Skip to first unread message

Ibrahim Awwal

unread,
Jul 5, 2024, 2:23:38 PM7/5/24
to chrome-debugging-protocol
Hi!

I was wondering, is there a way to get the ID of the default/persistent browser context? Target.getBrowserContexts returns only those created by Target.createBrowserContext and not the default one. One way to get that ID would be to create a new target without passing a browserContextId and then call Target.getTargetInfo to find its browserContextId, but I'm wondering if there's a way to get it without having to create a new Target. I know that you don't need to pass this ID to create a Target in the default context, but a library that I'm using kinda needs it for bookkeeping purposes so I was trying to determine the best way to get it.

Thank you for your help!

-Ibrahim

Alex Rudenko

unread,
Jul 8, 2024, 5:26:02 AM7/8/24
to chrome-debugging-protocol
You could also call Target.getTargets and see which browser context ids do not show up in the result of Target.getBrowserContexts. That requires for at least one target to exist in the default context (which is usually the case).

Ibrahim Awwal

unread,
Jul 9, 2024, 3:33:42 PM7/9/24
to chrome-debugging-protocol
Hi Alex,

That is actually what I've been doing so far, but I worried what might happen in the case that no tabs exist in the default context. So there's no better way to get that information directly? It would be nice if there was an API for that but I understand why that might not be a priority. Hopefully that will be sufficient for the Ferrum library for now, and maybe we can come up with a more reliable solution in the future.

Thanks,

-Ibrahim
Reply all
Reply to author
Forward
0 new messages