MCPcopy
hub / github.com/ChromeDevTools/chrome-devtools-mcp / #initializePage

Method #initializePage

src/PageCollector.ts:115–144  ·  view source on GitHub ↗
(page: Page)

Source from the content-addressed store, hash-verified

113 }
114
115 #initializePage(page: Page) {
116 if (this.storage.has(page)) {
117 return;
118 }
119 const idGenerator = createIdGenerator();
120 const storedLists: Array<Array<WithSymbolId<T>>> = [[]];
121 this.storage.set(page, storedLists);
122
123 const listeners = this.#listenersInitializer(value => {
124 const withId = value as WithSymbolId<T>;
125 withId[stableIdSymbol] = idGenerator();
126
127 const navigations = this.storage.get(page) ?? [[]];
128 navigations[0].push(withId);
129 });
130
131 listeners['framenavigated'] = (frame: Frame) => {
132 // Only split the storage on main frame navigation
133 if (frame !== page.mainFrame()) {
134 return;
135 }
136 this.splitAfterNavigation(page);
137 };
138
139 for (const [name, listener] of Object.entries(listeners)) {
140 page.on(name, listener as Handler<unknown>);
141 }
142
143 this.#listeners.set(page, listeners);
144 }
145
146 protected splitAfterNavigation(page: Page) {
147 const navigations = this.storage.get(page);

Callers 1

addPageMethod · 0.95

Calls 5

splitAfterNavigationMethod · 0.95
createIdGeneratorFunction · 0.85
hasMethod · 0.45
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected