diff --git a/lib/connection.js b/lib/connection.js index e4d394ed6..5e4cc7535 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -126,24 +126,13 @@ const connect_to_cri = async (target, options = {}) => { return initCRI(tgt, numRetries, options); }; -const closeConnection = async (promisesToBeResolvedBeforeCloseBrowser) => { +const closeConnection = async () => { if (_client) { // remove listeners other than JS dialog for beforeUnload on client first to stop executing them when closing await _client.removeAllListeners(); pageHandler.addJavascriptDialogOpeningListener(); - //TODO: Remove check once fixed https://bugs.chromium.org/p/chromium/issues/detail?id=1147809 - if (!defaultConfig.firefox && !(process.platform == 'win32' && defaultConfig.headful)) { + if (!defaultConfig.firefox) { await pageHandler.closePage(); - - await new Promise((resolve) => { - let timeout = setTimeout(() => { - resolve(); - }, defaultConfig.retryTimeout); - Promise.all(promisesToBeResolvedBeforeCloseBrowser).then(() => { - clearTimeout(timeout); - resolve(); - }); - }); } } defaultConfig.connectedToRemoteBrowser ? await _client.Browser.close() : await closeBrowser(); diff --git a/lib/taiko.js b/lib/taiko.js index 26666c819..4b6bdfa1d 100644 --- a/lib/taiko.js +++ b/lib/taiko.js @@ -135,7 +135,7 @@ module.exports.closeBrowser = async () => { const _closeBrowser = async () => { fetchHandler.resetInterceptors(); - await closeConnection(promisesToBeResolvedBeforeCloseBrowser); + await closeConnection(); }; /** @@ -2223,7 +2223,11 @@ module.exports.confirm = (message, callback) => dialog('confirm', message, callb * * @param {function} callback - Action to perform. Accept/Dismiss. */ -module.exports.beforeunload = (callback) => dialog('beforeunload', '', callback); +module.exports.beforeunload = () => { + console.warn( + 'beforeunload handler is not supported any more refer https://developer.chrome.com/docs/web-platform/deprecating-unload', + ); +}; /** * Evaluates script on element matching the given selector. @@ -2516,19 +2520,8 @@ module.exports.getConfig = getConfig; */ module.exports.setConfig = setConfig; -const promisesToBeResolvedBeforeCloseBrowser = []; - const dialog = (dialogType, dialogMessage, callback) => { validate(); - // TODO: Commented to fix issue with browser closing for unresolved events - // let resolver = null; - // if (dialogType === 'beforeunload') { - // promisesToBeResolvedBeforeCloseBrowser.push( - // new Promise((resolve) => { - // resolver = resolve; - // }), - // ); - // } let eventName = ''; if (isFunction(dialogMessage)) { eventName = dialogType; @@ -2537,10 +2530,7 @@ const dialog = (dialogType, dialogMessage, callback) => { eventName = createJsDialogEvent(dialogMessage, dialogType); eventRegexMap.set(eventName, new RegExp(dialogMessage)); } - return eventHandler.once(eventName, async (args) => { - await callback(args); - // resolver && resolver(); - }); + return eventHandler.once(eventName, callback); }; const createJsDialogEvent = (message, dType) => { diff --git a/test/unit-tests/beforeunload.test.js b/test/unit-tests/beforeunload.test.js index 2e6eaacaa..1973fd42d 100644 --- a/test/unit-tests/beforeunload.test.js +++ b/test/unit-tests/beforeunload.test.js @@ -16,7 +16,8 @@ let { let { createHtml, removeFile, openBrowserArgs } = require('./test-util'); const test_name = 'beforeunload'; -// TODO: Fix this test before merge +// TODO: Skip this test and remove the unload functionality +// Refer:https://developer.chrome.com/docs/web-platform/deprecating-unload xdescribe(test_name, () => { let filePath, filePath1; let called = false;