Skip to content

New browser tab event / notification #146

@michalkkkd

Description

@michalkkkd

Hi,
I'm intercepting the bodies of XHRs sent from my application to the user. I'm using this awesome library for this purpose.

Scenario:

  • Users open the main application site in a tab.
  • Users can open additional tabs (1-5) by right-clicking links to my application within that first tab.
    Technical Details:

Environment: Chromium browser on Windows 11
My current solution:

// Initialization of global instances:
globalCtx = context.Background()
globalDevt = devtool.New("http://127.0.0.1:9222")

// Periodically check for new tabs:
ticker := time.NewTicker(100 * time.Millisecond)
targets, err := globalDevt.List(globalCtx) 
for _, tab := range targets {
    if tab.Type == "page" { 
        tabConnection, err := rpcc.DialContext(globalCtx, target.WebSocketDebuggerURL)
        if err != nil {
            // Handle error  
        }
        tabClient := cdp.NewClient(tabConnection)
        // ... (Logic for XHR interception on this tabClient)
    }
}

Is there any better way to do this? I tried using gists avaialable on the web, but no luck.
I'm asking, because I have also second program connected to same chrome instance (yes, i have to have 2 programs connected to same browser using cdp :( ) and I think that this frequent querying for tabs may cause interferences I have between these 2 programs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions