MCPcopy
hub / github.com/mxschmitt/playwright-go / newPage

Function newPage

page.go:904–1028  ·  view source on GitHub ↗
(parent *channelOwner, objectType string, guid string, initializer map[string]any)

Source from the content-addressed store, hash-verified

902}
903
904func newPage(parent *channelOwner, objectType string, guid string, initializer map[string]any) *pageImpl {
905 viewportSize := &Size{}
906 if _, ok := initializer["viewportSize"].(map[string]any); ok {
907 viewportSize.Height = int(initializer["viewportSize"].(map[string]any)["height"].(float64))
908 viewportSize.Width = int(initializer["viewportSize"].(map[string]any)["width"].(float64))
909 }
910 bt := &pageImpl{
911 workers: make([]Worker, 0),
912 routes: make([]*routeHandlerEntry, 0),
913 bindings: safe.NewSyncMap[string, BindingCallFunction](),
914 viewportSize: viewportSize,
915 harRouters: make([]*harRouter, 0),
916 locatorHandlers: make(map[float64]*locatorHandlerEntry, 0),
917 }
918 bt.createChannelOwner(bt, parent, objectType, guid, initializer)
919 if closed, ok := initializer["isClosed"].(bool); ok {
920 bt.isClosed = closed
921 }
922 bt.browserContext = fromChannel(parent.channel).(*browserContextImpl)
923 bt.timeoutSettings = newTimeoutSettings(bt.browserContext.timeoutSettings)
924 mainframe := fromChannel(initializer["mainFrame"]).(*frameImpl)
925 mainframe.page = bt
926 bt.mainFrame = mainframe
927 bt.frames = []Frame{mainframe}
928 bt.mouse = newMouse(bt.channel)
929 bt.keyboard = newKeyboard(bt.channel)
930 bt.touchscreen = newTouchscreen(bt.channel)
931 bt.localStorage = newWebStorage(bt, "local")
932 bt.sessionStorage = newWebStorage(bt, "session")
933 bt.channel.On("bindingCall", func(params map[string]any) {
934 bt.onBinding(fromChannel(params["binding"]).(*bindingCallImpl))
935 })
936 bt.channel.On("close", bt.onClose)
937 bt.channel.On("crash", func() {
938 bt.Emit("crash", bt)
939 })
940 bt.channel.On("domcontentloaded", func() {
941 bt.Emit("domcontentloaded", bt)
942 })
943 bt.channel.On("fileChooser", func(ev map[string]any) {
944 bt.Emit("filechooser", newFileChooser(bt, fromChannel(ev["element"]).(*elementHandleImpl), ev["isMultiple"].(bool)))
945 })
946 bt.channel.On("frameAttached", func(ev map[string]any) {
947 bt.onFrameAttached(fromChannel(ev["frame"]).(*frameImpl))
948 })
949 bt.channel.On("frameDetached", func(ev map[string]any) {
950 bt.onFrameDetached(fromChannel(ev["frame"]).(*frameImpl))
951 })
952 bt.channel.On("viewportSizeChanged", func(ev map[string]any) {
953 // Keep viewportSize in sync with server-driven changes (e.g. a sized popup).
954 if vs, ok := ev["viewportSize"].(map[string]any); ok {
955 bt.viewportSize = &Size{
956 Width: int(vs["width"].(float64)),
957 Height: int(vs["height"].(float64)),
958 }
959 }
960 })
961 bt.channel.On("locatorHandlerTriggered", func(ev map[string]any) {

Callers 1

createObjectFactoryFunction · 0.85

Calls 15

onBindingMethod · 0.95
onFrameAttachedMethod · 0.95
onFrameDetachedMethod · 0.95
onRouteMethod · 0.95
VideoMethod · 0.95
onWebSocketRouteMethod · 0.95
onWorkerMethod · 0.95
OnCloseMethod · 0.95
closeErrorWithReasonMethod · 0.95
OnCrashMethod · 0.95
NewSyncMapFunction · 0.92

Tested by

no test coverage detected