playwright-core
Advanced tools
Comparing version 1.44.0-alpha-2024-04-24 to 1.44.0-alpha-2024-04-25
@@ -30,9 +30,9 @@ { | ||
"name": "firefox-beta", | ||
"revision": "1447", | ||
"revision": "1449", | ||
"installByDefault": false, | ||
"browserVersion": "125.0b3" | ||
"browserVersion": "126.0b1" | ||
}, | ||
{ | ||
"name": "webkit", | ||
"revision": "2001", | ||
"revision": "2002", | ||
"installByDefault": true, | ||
@@ -39,0 +39,0 @@ "revisionOverrides": { |
@@ -74,2 +74,5 @@ "use strict"; | ||
} | ||
_equals(locator) { | ||
return this._frame === locator._frame && this._selector === locator._selector; | ||
} | ||
page() { | ||
@@ -76,0 +79,0 @@ return this._frame.page(); |
@@ -311,21 +311,43 @@ "use strict"; | ||
} | ||
async addLocatorHandler(locator, handler) { | ||
async addLocatorHandler(locator, handler, options = {}) { | ||
if (locator._frame !== this._mainFrame) throw new Error(`Locator must belong to the main frame of this page`); | ||
if (options.times === 0) return; | ||
const { | ||
uid | ||
} = await this._channel.registerLocatorHandler({ | ||
selector: locator._selector | ||
selector: locator._selector, | ||
allowStayingVisible: options.allowStayingVisible | ||
}); | ||
this._locatorHandlers.set(uid, handler); | ||
this._locatorHandlers.set(uid, { | ||
locator, | ||
handler, | ||
times: options.times | ||
}); | ||
} | ||
async _onLocatorHandlerTriggered(uid) { | ||
let remove = false; | ||
try { | ||
const handler = this._locatorHandlers.get(uid); | ||
await (handler === null || handler === void 0 ? void 0 : handler()); | ||
if (handler && handler.times !== 0) { | ||
if (handler.times !== undefined) handler.times--; | ||
await handler.handler(handler.locator); | ||
} | ||
remove = (handler === null || handler === void 0 ? void 0 : handler.times) === 0; | ||
} finally { | ||
this._wrapApiCall(() => this._channel.resolveLocatorHandlerNoReply({ | ||
uid | ||
uid, | ||
remove | ||
}), true).catch(() => {}); | ||
} | ||
} | ||
async removeLocatorHandler(locator, handler) { | ||
for (const [uid, data] of this._locatorHandlers) { | ||
if (data.locator._equals(locator) && data.handler === handler) { | ||
this._locatorHandlers.delete(uid); | ||
await this._channel.unregisterLocatorHandlerNoReply({ | ||
uid | ||
}).catch(() => {}); | ||
} | ||
} | ||
} | ||
async waitForLoadState(state, options) { | ||
@@ -332,0 +354,0 @@ return await this._mainFrame.waitForLoadState(state, options); |
@@ -137,3 +137,3 @@ "use strict"; | ||
async registerLocatorHandler(params, metadata) { | ||
const uid = this._page.registerLocatorHandler(params.selector); | ||
const uid = this._page.registerLocatorHandler(params.selector, params.allowStayingVisible); | ||
return { | ||
@@ -144,4 +144,7 @@ uid | ||
async resolveLocatorHandlerNoReply(params, metadata) { | ||
this._page.resolveLocatorHandler(params.uid); | ||
this._page.resolveLocatorHandler(params.uid, params.remove); | ||
} | ||
async unregisterLocatorHandlerNoReply(params, metadata) { | ||
this._page.unregisterLocatorHandler(params.uid); | ||
} | ||
async emulateMedia(params, metadata) { | ||
@@ -148,0 +151,0 @@ await this._page.emulateMedia({ |
@@ -289,11 +289,13 @@ "use strict"; | ||
} | ||
registerLocatorHandler(selector) { | ||
registerLocatorHandler(selector, allowStayingVisible) { | ||
const uid = ++this._lastLocatorHandlerUid; | ||
this._locatorHandlers.set(uid, { | ||
selector | ||
selector, | ||
allowStayingVisible | ||
}); | ||
return uid; | ||
} | ||
resolveLocatorHandler(uid) { | ||
resolveLocatorHandler(uid, remove) { | ||
const handler = this._locatorHandlers.get(uid); | ||
if (remove) this._locatorHandlers.delete(uid); | ||
if (handler) { | ||
@@ -305,2 +307,5 @@ var _handler$resolved; | ||
} | ||
unregisterLocatorHandler(uid) { | ||
this._locatorHandlers.delete(uid); | ||
} | ||
async performLocatorHandlersCheckpoint(progress) { | ||
@@ -321,3 +326,9 @@ // Do not run locator handlers from inside locator handler callbacks to avoid deadlocks. | ||
progress.log(` found ${(0, _locatorGenerators.asLocator)(this.attribution.playwright.options.sdkLanguage, handler.selector)}, intercepting action to run the handler`); | ||
await this.openScope.race(handler.resolved).finally(() => --this._locatorHandlerRunningCounter); | ||
const promise = handler.resolved.then(async () => { | ||
progress.throwIfAborted(); | ||
if (!handler.allowStayingVisible) await this.mainFrame().waitForSelectorInternal(progress, handler.selector, { | ||
state: 'hidden' | ||
}); | ||
}); | ||
await this.openScope.race(promise).finally(() => --this._locatorHandlerRunningCounter); | ||
// Avoid side-effects after long-running operation. | ||
@@ -324,0 +335,0 @@ progress.throwIfAborted(); |
{ | ||
"name": "playwright-core", | ||
"version": "1.44.0-alpha-2024-04-24", | ||
"version": "1.44.0-alpha-2024-04-25", | ||
"description": "A high-level API to automate web browsers", | ||
@@ -5,0 +5,0 @@ "repository": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
7118433
99994