headzoo / surf

Stateful programmatic web browsing in Go.
MIT License
1.48k stars 159 forks source link

[todo] Support Tabs/Processes #23

Open headzoo opened 9 years ago

headzoo commented 9 years ago

I like that Surf is stateful. Actionable methods like Open() and Post() modify the state of the browser rather than returning some object representing the request. However I've run into some minor problems with this stateful approach. I would like to add support for tabs/processes so developers can configure the browser once, and then create any number of tabs/processes that do the actual work.

How a page is opened now:

bow := surf.NewBrowser()
err := bow.Open("http://golang.org")
if err != nil {
    panic(err)
}

How it would be opened with "tab" support.

// Create and configure a new browser.
bow := surf.NewBrowser()
bow.AddRequestHeader("User-Agent", "Surfbot 1.0")
bow.SetTransport(&http.Transport{})

// Create a new tab. The tab is essentially an instance
// of Browsable, and inherits it's configuration from
// the parent browser.
tab := bow.NewTab()
err := tab.Open("http://golang.org")
if err != nil {
    panic(err)
}

Still debating using the term "tab", which may be taking the browser terminology too far, but on the upside the concept behind a tab -- and how it works -- should be easily understood by developers.

The feature may be treading into "over engineered" territory. Will have to give it some thought.

lexesv commented 7 years ago

It would be great if each tab, can be add your own transport (a proxy, for example). And the function of closing (cleaned) tab.