playwright-go/worker.go
Can Stand d2aa790e89
Some checks failed
Go / Lint (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (chromium, oldstable, macos-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (chromium, oldstable, ubuntu-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (chromium, oldstable, windows-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (chromium, stable, macos-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (chromium, stable, ubuntu-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (chromium, stable, windows-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (firefox, oldstable, macos-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (firefox, oldstable, ubuntu-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (firefox, oldstable, windows-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (firefox, stable, macos-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (firefox, stable, ubuntu-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (firefox, stable, windows-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (webkit, oldstable, macos-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (webkit, oldstable, ubuntu-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (webkit, oldstable, windows-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (webkit, stable, macos-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (webkit, stable, ubuntu-latest) (push) Has been cancelled
Go / ${{ matrix.browser }} on ${{ matrix.os }}, go ${{ matrix.go }} (webkit, stable, windows-latest) (push) Has been cancelled
Go / test-examples (push) Has been cancelled
Docs / Deploy docs (push) Has been cancelled
Verify Types / verify (push) Has been cancelled
Go / finish (push) Has been cancelled
chore: maintain StorageState type (#583)
2026-02-23 09:13:11 -08:00

86 lines
2.0 KiB
Go

package playwright
type workerImpl struct {
channelOwner
page *pageImpl
context *browserContextImpl
}
func (w *workerImpl) URL() string {
return w.initializer["url"].(string)
}
func (w *workerImpl) Evaluate(expression string, options ...any) (any, error) {
var arg any
if len(options) == 1 {
arg = options[0]
}
result, err := w.channel.Send("evaluateExpression", map[string]any{
"expression": expression,
"arg": serializeArgument(arg),
})
if err != nil {
return nil, err
}
return parseResult(result), nil
}
func (w *workerImpl) EvaluateHandle(expression string, options ...any) (JSHandle, error) {
var arg any
if len(options) == 1 {
arg = options[0]
}
result, err := w.channel.Send("evaluateExpressionHandle", map[string]any{
"expression": expression,
"arg": serializeArgument(arg),
})
if err != nil {
return nil, err
}
return fromChannel(result).(*jsHandleImpl), nil
}
func (w *workerImpl) onClose() {
if w.page != nil {
w.page.Lock()
workers := make([]Worker, 0)
for i := 0; i < len(w.page.workers); i++ {
if w.page.workers[i] != w {
workers = append(workers, w.page.workers[i])
}
}
w.page.workers = workers
w.page.Unlock()
}
if w.context != nil {
w.context.Lock()
workers := make([]Worker, 0)
for i := 0; i < len(w.context.serviceWorkers); i++ {
if w.context.serviceWorkers[i] != w {
workers = append(workers, w.context.serviceWorkers[i])
}
}
w.context.serviceWorkers = workers
w.context.Unlock()
}
w.Emit("close", w)
}
func (w *workerImpl) OnClose(fn func(Worker)) {
w.On("close", fn)
}
func (w *workerImpl) OnConsole(fn func(ConsoleMessage)) {
w.On("console", fn)
}
func newWorker(parent *channelOwner, objectType string, guid string, initializer map[string]any) *workerImpl {
bt := &workerImpl{}
bt.createChannelOwner(bt, parent, objectType, guid, initializer)
bt.channel.On("close", bt.onClose)
bt.channel.On("console", func(ev map[string]any) {
bt.Emit("console", newConsoleMessage(ev))
})
return bt
}