Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
Remove goja type assertion
Browse files Browse the repository at this point in the history
The remote parser no longer works with goja so the result from evaluate
will not return a goja value. Now just type assert without goja.
  • Loading branch information
ankur22 committed Jan 31, 2024
1 parent 8f43269 commit e98cf77
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions common/screenshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/chromedp/cdproto/cdp"
"github.com/chromedp/cdproto/emulation"
cdppage "github.com/chromedp/cdproto/page"
"github.com/dop251/goja"

"github.com/grafana/xk6-browser/storage"
)
Expand Down Expand Up @@ -121,12 +120,14 @@ func (s *screenshotter) originalViewportSize(p *Page) (*Size, *Size, error) {
if err != nil {
return nil, nil, fmt.Errorf("getting viewport dimensions: %w", err)
}
r, ok := result.(goja.Object)
if !ok {
return nil, nil, fmt.Errorf("cannot convert to goja object: %w", err)

var returnVal Size
if err := convert(result, &returnVal); err != nil {
return nil, nil, fmt.Errorf("unpacking window size: %w", err)
}
viewportSize.Width = r.Get("width").ToFloat()
viewportSize.Height = r.Get("height").ToFloat()

viewportSize.Width = returnVal.Width
viewportSize.Height = returnVal.Height

return &viewportSize, &originalViewportSize, nil
}
Expand Down Expand Up @@ -279,12 +280,15 @@ func (s *screenshotter) screenshotElement(h *ElementHandle, opts *ElementHandleS
documentRect := bbox
rt := h.execCtx.vu.Runtime()
scrollOffset := h.Evaluate(`() => { return {x: window.scrollX, y: window.scrollY};}`)
switch s := scrollOffset.(type) {
case goja.Value:
documentRect.X += s.ToObject(rt).Get("x").ToFloat()
documentRect.Y += s.ToObject(rt).Get("y").ToFloat()

var returnVal Position
if err := convert(scrollOffset, &returnVal); err != nil {
return nil, fmt.Errorf("unpacking scroll offset: %w", err)
}

documentRect.X += returnVal.X
documentRect.Y += returnVal.Y

buf, err := s.screenshot(h.frame.page.session, documentRect.enclosingIntRect(), nil, format, opts.OmitBackground, opts.Quality, opts.Path)
if err != nil {
return nil, err
Expand Down

0 comments on commit e98cf77

Please sign in to comment.