browser icon indicating copy to clipboard operation
browser copied to clipboard

Add an id generator

Open karlseguin opened this issue 1 day ago • 1 comments

Create UUID v4.

Create prefixed ids. To support more of the CDP protocol, we need to remove the hard-coded IDs (session, browser context, frame, loader, ...) and be able to dynamically create them, i.e. creating a new BrowserContextId when Target.createBrowserContext is called.

var frame_id = Incremental(u16, "FRM"){};
frame_id.next() == "FRM-1"
frame_id.next() == "FRM-2"

Generation is allocation-free (the returned string is only valid until the next call to next()). This is not thread safe, each CDP instance will have its own generator (for each id it needs to generate).

The generated IDs are different than what Chrome uses, i.e. BROWSERSESSIONID597D9875C664CAC0. I looked at various drivers and none have any expectations beyond a string. Shorter IDs will be more efficient. Also, the ID can cheeply be converted to and from an integer, allowing for lookups via AutoHashMap(u16) instead of StringHashMap.

karlseguin avatar Feb 21 '25 11:02 karlseguin