Added global screenshot shortcut
This commit is contained in:
		@@ -4,6 +4,7 @@ import (
 | 
				
			|||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
	"log/slog"
 | 
						"log/slog"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -248,3 +249,28 @@ func (b playWrightBrowser) Close() error {
 | 
				
			|||||||
		b.browser.Close(),
 | 
							b.browser.Close(),
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func deferClose(cl io.Closer) {
 | 
				
			||||||
 | 
						_ = cl.Close()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Screenshot(ctx context.Context, target string, timeout time.Duration) ([]byte, error) {
 | 
				
			||||||
 | 
						browser, err := NewPlayWrightBrowser(PlayWrightBrowserOptions{
 | 
				
			||||||
 | 
							Timeout: &timeout,
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("error creating browser: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer deferClose(browser)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						doc, err := browser.Open(ctx, target, OpenPageOptions{})
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("error opening page: %w", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer deferClose(doc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return doc.Screenshot()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user