Skip to content

Commit

Permalink
Move windowId calculation to the server-side (#5050)
Browse files Browse the repository at this point in the history
  • Loading branch information
miherlosev committed May 7, 2020
1 parent 59631dc commit ead0244
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/browser/provider/built-in/dedicated/chrome/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default {
runtimeInfo.activeWindowId = null;

if (allowMultipleWindows)
runtimeInfo.activeWindowId = await this.calculateWindowId(browserId);
runtimeInfo.activeWindowId = this.calculateWindowId();

await cdp.createClient(runtimeInfo);

Expand Down
2 changes: 1 addition & 1 deletion src/browser/provider/built-in/dedicated/firefox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default {
runtimeInfo.activeWindowId = null;

if (allowMultipleWindows)
runtimeInfo.activeWindowId = await this.calculateWindowId(browserId);
runtimeInfo.activeWindowId = this.calculateWindowId();

if (runtimeInfo.marionettePort)
runtimeInfo.marionetteClient = await this._createMarionetteClient(runtimeInfo);
Expand Down
2 changes: 1 addition & 1 deletion src/browser/provider/built-in/locally-installed.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default {
let activeWindowId = null;

if (allowMultipleWindows)
activeWindowId = await this.calculateWindowId(browserId);
activeWindowId = this.calculateWindowId();

this.openedBrowsers[browserId] = { activeWindowId };
},
Expand Down
8 changes: 1 addition & 7 deletions src/browser/provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { dirname } from 'path';
import makeDir from 'make-dir';
import BrowserConnection from '../connection';
import delay from '../../utils/delay';
import { GET_TITLE_SCRIPT, GET_WINDOW_DIMENSIONS_INFO_SCRIPT, GET_WINDOW_ID_SCRIPT } from './utils/client-functions';
import { GET_TITLE_SCRIPT, GET_WINDOW_DIMENSIONS_INFO_SCRIPT } from './utils/client-functions';
import WARNING_MESSAGE from '../../notifications/warning-message';
import { Dictionary } from '../../configuration/interfaces';

Expand Down Expand Up @@ -85,12 +85,6 @@ export default class BrowserProvider {
return connection.idle;
}

private async _calculateWindowId (browserId: string): Promise<void> {
const windowId = await this.plugin.runInitScript(browserId, GET_WINDOW_ID_SCRIPT);

this.setActiveWindowId(browserId, windowId);
}

private async _calculateResizeCorrections (browserId: string): Promise<void> {
if (!this._isBrowserIdle(browserId))
return;
Expand Down
6 changes: 3 additions & 3 deletions src/browser/provider/plugin-host.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import promisifyEvent from 'promisify-event';
import BROWSER_JOB_RESULT from '../../runner/browser-job-result';
import BrowserConnection from '../connection';
import WARNING_MESSAGE from '../../notifications/warning-message';
import { GET_WINDOW_ID_SCRIPT } from '../provider/utils/client-functions';
import { generateUniqueId } from 'testcafe-hammerhead';

const name = Symbol();

Expand All @@ -29,8 +29,8 @@ export default class BrowserProviderPluginHost {
return connection.runInitScript(`(${code})()`);
}

async calculateWindowId (browserId) {
return this.runInitScript(browserId, GET_WINDOW_ID_SCRIPT);
calculateWindowId () {
return generateUniqueId();
}

waitForConnectionReady (browserId) {
Expand Down
11 changes: 1 addition & 10 deletions src/browser/provider/utils/client-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,8 @@ function getWindowDimensionsInfo () {
availableHeight: screen.availHeight
};
}

function getWindowId () {
var array = new Uint16Array(1);
var crypto = window.crypto || window.msCrypto;

crypto.getRandomValues(array);

return array[0].toString();
}
/*eslint-disable no-undef, no-var*/

export const GET_TITLE_SCRIPT = getTitle.toString();
export const GET_WINDOW_DIMENSIONS_INFO_SCRIPT = getWindowDimensionsInfo.toString();
export const GET_WINDOW_ID_SCRIPT = getWindowId.toString();

0 comments on commit ead0244

Please sign in to comment.