(ctx context.Context)
| 50 | } |
| 51 | |
| 52 | func (s *BrowserSource) Fetch(ctx context.Context) (document string, err error) { |
| 53 | if s == nil { |
| 54 | return "", fmt.Errorf("fab: browser source is not initialized") |
| 55 | } |
| 56 | |
| 57 | browserPath := strings.TrimSpace(s.BrowserPath) |
| 58 | if browserPath == "" { |
| 59 | resolved, resolveErr := resolveBrowserOverride() |
| 60 | if resolveErr != nil { |
| 61 | return "", resolveErr |
| 62 | } |
| 63 | browserPath = resolved |
| 64 | } |
| 65 | |
| 66 | url := strings.TrimSpace(s.URL) |
| 67 | if url == "" { |
| 68 | url = defaultHomepageURL |
| 69 | } |
| 70 | |
| 71 | userAgent := strings.TrimSpace(s.UserAgent) |
| 72 | if userAgent == "" { |
| 73 | userAgent = defaultBrowserUserAgent |
| 74 | } |
| 75 | |
| 76 | timeout := s.Timeout |
| 77 | if timeout <= 0 { |
| 78 | timeout = 60 * time.Second |
| 79 | } |
| 80 | |
| 81 | postLoadDelay := s.PostLoadDelay |
| 82 | if postLoadDelay <= 0 { |
| 83 | postLoadDelay = 1500 * time.Millisecond |
| 84 | } |
| 85 | |
| 86 | s.mu.Lock() |
| 87 | defer s.mu.Unlock() |
| 88 | |
| 89 | browser, err := s.ensureBrowserLocked(browserPath) |
| 90 | if err != nil { |
| 91 | return "", err |
| 92 | } |
| 93 | |
| 94 | browserContext, err := browser.NewContext(playwright.BrowserNewContextOptions{ |
| 95 | Locale: playwright.String("en-US"), |
| 96 | UserAgent: playwright.String(userAgent), |
| 97 | Viewport: &playwright.Size{ |
| 98 | Width: 1440, |
| 99 | Height: 900, |
| 100 | }, |
| 101 | }) |
| 102 | if err != nil { |
| 103 | s.resetLocked() |
| 104 | return "", fmt.Errorf("fab: create firefox context: %w", err) |
| 105 | } |
| 106 | defer func() { |
| 107 | if closeErr := browserContext.Close(); err == nil && closeErr != nil { |
| 108 | err = fmt.Errorf("fab: close firefox context: %w", closeErr) |
| 109 | } |
nothing calls this directly
no test coverage detected