Skip to content

Conversation

@OmkarBansod02
Copy link
Contributor

It eliminate 8-10s lag in search providers

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Greptile Summary

This PR optimizes the new tab search provider execution by eliminating 8-10 second lag through a URL-based approach rather than DOM manipulation. The built-in providers (ChatGPT, Claude, Google) now use native query parameter support (?q=%s) in their urlPattern fields, allowing the query to be embedded directly in the initial navigation URL. This bypasses the previous flow that opened the page, waited for load, injected the query via DOM manipulation, and submitted the form. As a secondary optimization, timeout values were reduced from 8s to 3s and retry attempts from 5 to 2, since the DOM injection path is now only hit by custom providers without %s placeholders.

PR Description Notes:

  • Typo in PR title: "serach" should be "search"
  • PR description is minimal and could benefit from more technical detail

Important Files Changed

Filename Score Overview
src/newtab/stores/providerStore.ts 3/5 Switches built-in providers (ChatGPT, Claude, Google) from DOM-based query injection to URL query parameters; reduces timeouts (8s→3s) and retries (5→2); leaves DOM injection code for custom provider backward compatibility

Confidence score: 3/5

  • This PR should significantly improve performance for built-in providers but leaves dead code paths that need cleanup
  • Score reflects that while the core optimization is sound, the DOM manipulation fields (autoSubmit, focusBeforeSubmit, submitKey) are now dead code for all built-in providers yet remain in the schema and logic branches (lines 600-619), violating custom rule 9b045db4-2630-428c-95b7-ccf048d34547 which mandates removing unused code rather than leaving it dormant
  • The reduced timeout (3s) and retry count (2) should be tested across slow networks to ensure custom providers still work reliably; the needsDomWork check (line 558) now only evaluates true for custom providers, but the aggressive timeout reduction could cause failures for legitimate custom providers that need DOM manipulation

Sequence Diagram

sequenceDiagram
    participant User
    participant NewTabUI as "New Tab UI"
    participant ProviderStore as "Provider Store"
    participant BrowserOS as "BrowserOS Adapter"
    participant Tab as "Browser Tab"

    User->>NewTabUI: "Enter search query"
    User->>NewTabUI: "Select provider/agent"
    
    alt Execute Provider Action
        NewTabUI->>ProviderStore: "executeProviderAction(provider, query)"
        ProviderStore->>ProviderStore: "Log metric (newtab.execute_provider)"
        
        alt URL-based Provider
            ProviderStore->>ProviderStore: "Build target URL with query"
            
            alt Open in New Tab
                ProviderStore->>Tab: "chrome.tabs.create(targetUrl)"
            else Open in Current Tab
                ProviderStore->>Tab: "chrome.tabs.update(targetUrl)"
            end
            
            alt Needs DOM Work (no placeholder)
                ProviderStore->>BrowserOS: "Poll getPageLoadStatus(tabId)"
                BrowserOS-->>ProviderStore: "isDOMContentLoaded status"
                ProviderStore->>ProviderStore: "Wait post-load delay (200ms)"
                ProviderStore->>ProviderStore: "buildQueryInjectionScript(query)"
                ProviderStore->>BrowserOS: "executeJavaScript(tabId, script)"
                BrowserOS->>Tab: "Inject query into input field"
                Tab-->>BrowserOS: "Injection result"
                BrowserOS-->>ProviderStore: "Query injected status"
                
                alt Focus Before Submit
                    ProviderStore->>BrowserOS: "executeJavaScript(focus script)"
                    BrowserOS->>Tab: "Focus input element"
                end
                
                alt Auto Submit
                    ProviderStore->>BrowserOS: "sendKeys(tabId, submitKey)"
                    BrowserOS->>Tab: "Send Enter key"
                end
            end
        else Sidepanel Provider
            ProviderStore->>Tab: "chrome.tabs.query(active tab)"
            Tab-->>ProviderStore: "Active tab ID"
            ProviderStore->>Tab: "chrome.runtime.sendMessage(NEWTAB_EXECUTE_QUERY)"
        end
        
    else Execute Agent
        NewTabUI->>ProviderStore: "executeAgent(agent, query, isBuilder)"
        ProviderStore->>ProviderStore: "Log metric (newtab.execute_agent)"
        ProviderStore->>Tab: "chrome.tabs.query(active tab)"
        Tab-->>ProviderStore: "Active tab ID"
        ProviderStore->>ProviderStore: "Build final steps array"
        ProviderStore->>Tab: "chrome.runtime.sendMessage(NEWTAB_EXECUTE_QUERY)"
    end
Loading

Additional Comments (2)

  1. src/newtab/stores/providerStore.ts, line 600-611 (link)

    logic: focusBeforeSubmit is always undefined now (removed from default providers), so this code is unreachable for built-in providers

    Context Used: Rule from dashboard - Remove unused/dead code rather than leaving it in the codebase. If functionality might be needed lat... (source)

  2. src/newtab/stores/providerStore.ts, line 614-619 (link)

    logic: autoSubmit is always undefined now (removed from default providers), so this code is unreachable for built-in providers

    Context Used: Rule from dashboard - Remove unused/dead code rather than leaving it in the codebase. If functionality might be needed lat... (source)

Context used:

  • Rule from dashboard - Remove unused/dead code rather than leaving it in the codebase. If functionality might be needed lat... (source)

1 file reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@felarof99 felarof99 merged commit 06178ca into browseros-ai:main Oct 23, 2025
1 check passed
@github-actions github-actions bot locked and limited conversation to collaborators Oct 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants