Skip to content

Commit

Permalink
Update page.go
Browse files Browse the repository at this point in the history
  • Loading branch information
showurl committed Feb 27, 2023
1 parent ab75a24 commit 2ab4b03
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions page.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,31 @@ import (
"github.com/cherish-chat/chatgpt/config"
"github.com/playwright-community/playwright-go"
"github.com/sirupsen/logrus"
"time"
"log"
)

// Deprecated 请使用GetPage
func (h *Helper) MustGetPage(id string) playwright.Page {
if page, ok := h.pageMap.Load(id); ok {
return page.(playwright.Page)
}
var page playwright.Page
for {
var err error
page, err = h.NewPage(id)
if err != nil {
logrus.Errorf("Error while creating new page: %v", err)
time.Sleep(time.Second * 1)
continue
}
break
var err error
page, err = h.NewPage(id)
if err != nil {
logrus.Errorf("Error while creating new page: %v", err)
log.Fatalf("Error while creating new page: %v", err)
}
return page
}

func (h *Helper) GetPage(id string) (playwright.Page, error) {
if page, ok := h.pageMap.Load(id); ok {
return page.(playwright.Page), nil
}
return h.NewPage(id)
}

func (h *Helper) NewPage(id string) (playwright.Page, error) {
page, err := h.browser.NewPage()
if err != nil {
Expand Down

0 comments on commit 2ab4b03

Please sign in to comment.