Skip to content

Commit

Permalink
Add exportTo helper
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Nov 5, 2024
1 parent 946e4cb commit ad80bc7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions browser/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ func panicIfFatalError(ctx context.Context, err error) {
}
}

// exportTo exports the Sobek value to a Go value.
// It returns the zero value of T if obj does not exist in the Sobek runtime.
// It's caller's responsibility to check for nilness.
func exportTo[T any](rt *sobek.Runtime, obj sobek.Value) (T, error) {
var t T
if !sobekValueExists(obj) {
return t, nil
}
err := rt.ExportTo(obj, &t)
return t, err //nolint:wrapcheck
}

// exportArg exports the value and returns it.
// It returns nil if the value is undefined or null.
func exportArg(gv sobek.Value) any {
Expand Down
23 changes: 23 additions & 0 deletions examples/geo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { browser } from 'k6/x/browser/async';
import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js';

export const options = {
scenarios: {
ui: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
thresholds: {
checks: ["rate==1.0"]
}
}

export default async function() {
const context = await browser.newContext();
await context.setGeolocation({ latitude: 37.7749, slongitude: -122.4194, accuracy: 1 });
}

0 comments on commit ad80bc7

Please sign in to comment.