Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New browser tab event / notification #146

Open
michalkkkd opened this issue May 1, 2024 · 0 comments
Open

New browser tab event / notification #146

michalkkkd opened this issue May 1, 2024 · 0 comments

Comments

@michalkkkd
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant