2021-12-10 02:21:17 +01:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the 'License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-11-03 21:47:51 +01:00
|
|
|
import type EventEmitter from 'events';
|
2021-12-10 02:21:17 +01:00
|
|
|
import fs from 'fs';
|
|
|
|
|
import path from 'path';
|
2022-09-21 03:41:51 +02:00
|
|
|
import type * as channels from '@protocol/channels';
|
2022-04-08 05:18:22 +02:00
|
|
|
import { ManualPromise } from '../../utils/manualPromise';
|
2022-04-07 22:55:44 +02:00
|
|
|
import { assert, createGuid } from '../../utils';
|
2022-08-25 20:58:41 +02:00
|
|
|
import type { RootDispatcher } from './dispatcher';
|
2022-04-06 23:57:14 +02:00
|
|
|
import { Dispatcher } from './dispatcher';
|
2022-04-19 02:50:25 +02:00
|
|
|
import { yazl, yauzl } from '../../zipBundle';
|
2022-06-19 05:24:55 +02:00
|
|
|
import { ZipFile } from '../../utils/zipFile';
|
2022-09-21 03:41:51 +02:00
|
|
|
import type * as har from '@trace/har';
|
2022-06-19 05:24:55 +02:00
|
|
|
import type { HeadersArray } from '../types';
|
2022-09-27 22:05:06 +02:00
|
|
|
import { JsonPipeDispatcher } from '../dispatchers/jsonPipeDispatcher';
|
|
|
|
|
import { WebSocketTransport } from '../transport';
|
2022-11-03 21:47:51 +01:00
|
|
|
import { SocksInterceptor } from '../socksInterceptor';
|
2022-09-27 22:05:06 +02:00
|
|
|
import type { CallMetadata } from '../instrumentation';
|
|
|
|
|
import { getUserAgent } from '../../common/userAgent';
|
|
|
|
|
import type { Progress } from '../progress';
|
|
|
|
|
import { ProgressController } from '../progress';
|
|
|
|
|
import { fetchData } from '../../common/netUtils';
|
|
|
|
|
import type { HTTPRequestParams } from '../../common/netUtils';
|
|
|
|
|
import type http from 'http';
|
|
|
|
|
import type { Playwright } from '../playwright';
|
|
|
|
|
import { SdkObject } from '../../server/instrumentation';
|
2022-04-18 20:31:58 +02:00
|
|
|
|
2022-08-25 20:58:41 +02:00
|
|
|
export class LocalUtilsDispatcher extends Dispatcher<{ guid: string }, channels.LocalUtilsChannel, RootDispatcher> implements channels.LocalUtilsChannel {
|
2021-12-10 02:21:17 +01:00
|
|
|
_type_LocalUtils: boolean;
|
2022-06-19 05:24:55 +02:00
|
|
|
private _harBakends = new Map<string, HarBackend>();
|
2022-06-09 05:29:03 +02:00
|
|
|
|
2022-09-27 22:05:06 +02:00
|
|
|
constructor(scope: RootDispatcher, playwright: Playwright) {
|
|
|
|
|
const localUtils = new SdkObject(playwright, 'localUtils', 'localUtils');
|
|
|
|
|
super(scope, localUtils, 'LocalUtils', {});
|
2021-12-10 02:21:17 +01:00
|
|
|
this._type_LocalUtils = true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-27 22:05:06 +02:00
|
|
|
async zip(params: channels.LocalUtilsZipParams, metadata: CallMetadata): Promise<void> {
|
2021-12-10 02:21:17 +01:00
|
|
|
const promise = new ManualPromise<void>();
|
|
|
|
|
const zipFile = new yazl.ZipFile();
|
|
|
|
|
(zipFile as any as EventEmitter).on('error', error => promise.reject(error));
|
|
|
|
|
|
|
|
|
|
for (const entry of params.entries) {
|
|
|
|
|
try {
|
|
|
|
|
if (fs.statSync(entry.value).isFile())
|
|
|
|
|
zipFile.addFile(entry.value, entry.name);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!fs.existsSync(params.zipFile)) {
|
|
|
|
|
// New file, just compress the entries.
|
|
|
|
|
await fs.promises.mkdir(path.dirname(params.zipFile), { recursive: true });
|
|
|
|
|
zipFile.end(undefined, () => {
|
|
|
|
|
zipFile.outputStream.pipe(fs.createWriteStream(params.zipFile)).on('close', () => promise.resolve());
|
|
|
|
|
});
|
|
|
|
|
return promise;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// File already exists. Repack and add new entries.
|
|
|
|
|
const tempFile = params.zipFile + '.tmp';
|
|
|
|
|
await fs.promises.rename(params.zipFile, tempFile);
|
|
|
|
|
|
|
|
|
|
yauzl.open(tempFile, (err, inZipFile) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
promise.reject(err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
assert(inZipFile);
|
|
|
|
|
let pendingEntries = inZipFile.entryCount;
|
|
|
|
|
inZipFile.on('entry', entry => {
|
|
|
|
|
inZipFile.openReadStream(entry, (err, readStream) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
promise.reject(err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
zipFile.addReadStream(readStream!, entry.fileName);
|
|
|
|
|
if (--pendingEntries === 0) {
|
|
|
|
|
zipFile.end(undefined, () => {
|
|
|
|
|
zipFile.outputStream.pipe(fs.createWriteStream(params.zipFile)).on('close', () => {
|
|
|
|
|
fs.promises.unlink(tempFile).then(() => {
|
|
|
|
|
promise.resolve();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
return promise;
|
|
|
|
|
}
|
2022-06-19 05:24:55 +02:00
|
|
|
|
2022-09-27 22:05:06 +02:00
|
|
|
async harOpen(params: channels.LocalUtilsHarOpenParams, metadata: CallMetadata): Promise<channels.LocalUtilsHarOpenResult> {
|
2022-06-19 05:24:55 +02:00
|
|
|
let harBackend: HarBackend;
|
|
|
|
|
if (params.file.endsWith('.zip')) {
|
|
|
|
|
const zipFile = new ZipFile(params.file);
|
2022-06-20 20:07:53 +02:00
|
|
|
const entryNames = await zipFile.entries();
|
|
|
|
|
const harEntryName = entryNames.find(e => e.endsWith('.har'));
|
|
|
|
|
if (!harEntryName)
|
|
|
|
|
return { error: 'Specified archive does not have a .har file' };
|
|
|
|
|
const har = await zipFile.read(harEntryName);
|
2022-06-22 21:16:29 +02:00
|
|
|
const harFile = JSON.parse(har.toString()) as har.HARFile;
|
2022-06-20 20:07:53 +02:00
|
|
|
harBackend = new HarBackend(harFile, null, zipFile);
|
2022-06-19 05:24:55 +02:00
|
|
|
} else {
|
2022-06-22 21:16:29 +02:00
|
|
|
const harFile = JSON.parse(await fs.promises.readFile(params.file, 'utf-8')) as har.HARFile;
|
2022-06-20 20:07:53 +02:00
|
|
|
harBackend = new HarBackend(harFile, path.dirname(params.file), null);
|
2022-06-19 05:24:55 +02:00
|
|
|
}
|
|
|
|
|
this._harBakends.set(harBackend.id, harBackend);
|
|
|
|
|
return { harId: harBackend.id };
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-27 22:05:06 +02:00
|
|
|
async harLookup(params: channels.LocalUtilsHarLookupParams, metadata: CallMetadata): Promise<channels.LocalUtilsHarLookupResult> {
|
2022-06-19 05:24:55 +02:00
|
|
|
const harBackend = this._harBakends.get(params.harId);
|
|
|
|
|
if (!harBackend)
|
|
|
|
|
return { action: 'error', message: `Internal error: har was not opened` };
|
2022-07-05 17:58:34 +02:00
|
|
|
return await harBackend.lookup(params.url, params.method, params.headers, params.postData, params.isNavigationRequest);
|
2022-06-19 05:24:55 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-27 22:05:06 +02:00
|
|
|
async harClose(params: channels.LocalUtilsHarCloseParams, metadata: CallMetadata): Promise<void> {
|
2022-06-19 05:24:55 +02:00
|
|
|
const harBackend = this._harBakends.get(params.harId);
|
|
|
|
|
if (harBackend) {
|
|
|
|
|
this._harBakends.delete(harBackend.id);
|
|
|
|
|
harBackend.dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-29 00:09:36 +02:00
|
|
|
|
2022-09-27 22:05:06 +02:00
|
|
|
async harUnzip(params: channels.LocalUtilsHarUnzipParams, metadata: CallMetadata): Promise<void> {
|
2022-06-29 00:09:36 +02:00
|
|
|
const dir = path.dirname(params.zipFile);
|
|
|
|
|
const zipFile = new ZipFile(params.zipFile);
|
|
|
|
|
for (const entry of await zipFile.entries()) {
|
|
|
|
|
const buffer = await zipFile.read(entry);
|
|
|
|
|
if (entry === 'har.har')
|
|
|
|
|
await fs.promises.writeFile(params.harFile, buffer);
|
|
|
|
|
else
|
|
|
|
|
await fs.promises.writeFile(path.join(dir, entry), buffer);
|
|
|
|
|
}
|
|
|
|
|
zipFile.close();
|
|
|
|
|
await fs.promises.unlink(params.zipFile);
|
|
|
|
|
}
|
2022-09-27 22:05:06 +02:00
|
|
|
|
|
|
|
|
async connect(params: channels.LocalUtilsConnectParams, metadata: CallMetadata): Promise<channels.LocalUtilsConnectResult> {
|
|
|
|
|
const controller = new ProgressController(metadata, this._object as SdkObject);
|
|
|
|
|
controller.setLogName('browser');
|
|
|
|
|
return await controller.run(async progress => {
|
2022-12-09 20:16:29 +01:00
|
|
|
const wsHeaders = {
|
|
|
|
|
'User-Agent': getUserAgent(),
|
|
|
|
|
'x-playwright-proxy': params.exposeNetwork ?? '',
|
|
|
|
|
...params.headers,
|
|
|
|
|
};
|
2022-09-27 22:05:06 +02:00
|
|
|
const wsEndpoint = await urlToWSEndpoint(progress, params.wsEndpoint);
|
|
|
|
|
|
2022-12-09 20:16:29 +01:00
|
|
|
const transport = await WebSocketTransport.connect(progress, wsEndpoint, wsHeaders, true);
|
|
|
|
|
const socksInterceptor = new SocksInterceptor(transport, params.exposeNetwork, params.socksProxyRedirectPortForTest);
|
2022-09-27 22:05:06 +02:00
|
|
|
const pipe = new JsonPipeDispatcher(this);
|
|
|
|
|
transport.onmessage = json => {
|
2022-11-03 21:47:51 +01:00
|
|
|
if (socksInterceptor.interceptMessage(json))
|
2022-09-27 22:05:06 +02:00
|
|
|
return;
|
|
|
|
|
const cb = () => {
|
|
|
|
|
try {
|
|
|
|
|
pipe.dispatch(json);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
transport.close();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
if (params.slowMo)
|
|
|
|
|
setTimeout(cb, params.slowMo);
|
|
|
|
|
else
|
|
|
|
|
cb();
|
|
|
|
|
};
|
|
|
|
|
pipe.on('message', message => {
|
|
|
|
|
transport.send(message);
|
|
|
|
|
});
|
|
|
|
|
transport.onclose = () => {
|
|
|
|
|
socksInterceptor?.cleanup();
|
|
|
|
|
pipe.wasClosed();
|
|
|
|
|
};
|
|
|
|
|
pipe.on('close', () => transport.close());
|
|
|
|
|
return { pipe };
|
|
|
|
|
}, params.timeout || 0);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-19 05:24:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const redirectStatus = [301, 302, 303, 307, 308];
|
|
|
|
|
|
|
|
|
|
class HarBackend {
|
|
|
|
|
readonly id = createGuid();
|
2022-06-22 21:16:29 +02:00
|
|
|
private _harFile: har.HARFile;
|
2022-06-19 05:24:55 +02:00
|
|
|
private _zipFile: ZipFile | null;
|
2022-06-20 20:07:53 +02:00
|
|
|
private _baseDir: string | null;
|
2022-06-19 05:24:55 +02:00
|
|
|
|
2022-06-22 21:16:29 +02:00
|
|
|
constructor(harFile: har.HARFile, baseDir: string | null, zipFile: ZipFile | null) {
|
2022-06-19 05:24:55 +02:00
|
|
|
this._harFile = harFile;
|
2022-06-20 20:07:53 +02:00
|
|
|
this._baseDir = baseDir;
|
2022-06-19 05:24:55 +02:00
|
|
|
this._zipFile = zipFile;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-20 23:14:40 +02:00
|
|
|
async lookup(url: string, method: string, headers: HeadersArray, postData: Buffer | undefined, isNavigationRequest: boolean): Promise<{
|
2022-06-19 05:24:55 +02:00
|
|
|
action: 'error' | 'redirect' | 'fulfill' | 'noentry',
|
|
|
|
|
message?: string,
|
|
|
|
|
redirectURL?: string,
|
|
|
|
|
status?: number,
|
|
|
|
|
headers?: HeadersArray,
|
2022-07-05 17:58:34 +02:00
|
|
|
body?: Buffer }> {
|
2022-06-19 05:24:55 +02:00
|
|
|
let entry;
|
|
|
|
|
try {
|
2022-06-20 23:14:40 +02:00
|
|
|
entry = await this._harFindResponse(url, method, headers, postData);
|
2022-06-19 05:24:55 +02:00
|
|
|
} catch (e) {
|
|
|
|
|
return { action: 'error', message: 'HAR error: ' + e.message };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!entry)
|
|
|
|
|
return { action: 'noentry' };
|
|
|
|
|
|
|
|
|
|
// If navigation is being redirected, restart it with the final url to ensure the document's url changes.
|
|
|
|
|
if (entry.request.url !== url && isNavigationRequest)
|
|
|
|
|
return { action: 'redirect', redirectURL: entry.request.url };
|
|
|
|
|
|
|
|
|
|
const response = entry.response;
|
2022-06-20 23:14:40 +02:00
|
|
|
try {
|
|
|
|
|
const buffer = await this._loadContent(response.content);
|
|
|
|
|
return {
|
|
|
|
|
action: 'fulfill',
|
|
|
|
|
status: response.status,
|
|
|
|
|
headers: response.headers,
|
2022-07-05 17:58:34 +02:00
|
|
|
body: buffer,
|
2022-06-20 23:14:40 +02:00
|
|
|
};
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return { action: 'error', message: e.message };
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-19 05:24:55 +02:00
|
|
|
|
2022-06-22 23:44:12 +02:00
|
|
|
private async _loadContent(content: { text?: string, encoding?: string, _file?: string }): Promise<Buffer> {
|
|
|
|
|
const file = content._file;
|
2022-06-20 23:14:40 +02:00
|
|
|
let buffer: Buffer;
|
2022-06-22 23:44:12 +02:00
|
|
|
if (file) {
|
2022-06-20 23:14:40 +02:00
|
|
|
if (this._zipFile)
|
2022-06-22 23:44:12 +02:00
|
|
|
buffer = await this._zipFile.read(file);
|
2022-06-20 23:14:40 +02:00
|
|
|
else
|
2022-06-22 23:44:12 +02:00
|
|
|
buffer = await fs.promises.readFile(path.resolve(this._baseDir!, file));
|
2022-06-20 23:14:40 +02:00
|
|
|
} else {
|
|
|
|
|
buffer = Buffer.from(content.text || '', content.encoding === 'base64' ? 'base64' : 'utf-8');
|
2022-06-19 05:24:55 +02:00
|
|
|
}
|
2022-06-20 23:14:40 +02:00
|
|
|
return buffer;
|
2022-06-19 05:24:55 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-22 21:16:29 +02:00
|
|
|
private async _harFindResponse(url: string, method: string, headers: HeadersArray, postData: Buffer | undefined): Promise<har.Entry | undefined> {
|
2022-06-19 05:24:55 +02:00
|
|
|
const harLog = this._harFile.log;
|
2022-06-22 21:16:29 +02:00
|
|
|
const visited = new Set<har.Entry>();
|
2022-06-19 05:24:55 +02:00
|
|
|
while (true) {
|
2022-06-22 21:16:29 +02:00
|
|
|
const entries: har.Entry[] = [];
|
2022-06-21 02:22:32 +02:00
|
|
|
for (const candidate of harLog.entries) {
|
|
|
|
|
if (candidate.request.url !== url || candidate.request.method !== method)
|
|
|
|
|
continue;
|
|
|
|
|
if (method === 'POST' && postData && candidate.request.postData) {
|
|
|
|
|
const buffer = await this._loadContent(candidate.request.postData);
|
|
|
|
|
if (!buffer.equals(postData))
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
entries.push(candidate);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-20 23:14:40 +02:00
|
|
|
if (!entries.length)
|
2022-06-19 05:24:55 +02:00
|
|
|
return;
|
2022-06-20 23:14:40 +02:00
|
|
|
|
2022-06-21 02:22:32 +02:00
|
|
|
let entry = entries[0];
|
2022-06-20 23:14:40 +02:00
|
|
|
|
2022-06-21 02:22:32 +02:00
|
|
|
// Disambiguate using headers - then one with most matching headers wins.
|
2022-06-20 23:14:40 +02:00
|
|
|
if (entries.length > 1) {
|
2022-06-22 21:16:29 +02:00
|
|
|
const list: { candidate: har.Entry, matchingHeaders: number }[] = [];
|
2022-06-21 02:22:32 +02:00
|
|
|
for (const candidate of entries) {
|
|
|
|
|
const matchingHeaders = countMatchingHeaders(candidate.request.headers, headers);
|
|
|
|
|
list.push({ candidate, matchingHeaders });
|
2022-06-20 23:14:40 +02:00
|
|
|
}
|
2022-06-21 02:22:32 +02:00
|
|
|
list.sort((a, b) => b.matchingHeaders - a.matchingHeaders);
|
|
|
|
|
entry = list[0].candidate;
|
2022-06-21 01:41:53 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-19 05:24:55 +02:00
|
|
|
if (visited.has(entry))
|
|
|
|
|
throw new Error(`Found redirect cycle for ${url}`);
|
2022-06-20 23:14:40 +02:00
|
|
|
|
2022-06-19 05:24:55 +02:00
|
|
|
visited.add(entry);
|
|
|
|
|
|
2022-06-20 23:14:40 +02:00
|
|
|
// Follow redirects.
|
2022-06-19 05:24:55 +02:00
|
|
|
const locationHeader = entry.response.headers.find(h => h.name.toLowerCase() === 'location');
|
|
|
|
|
if (redirectStatus.includes(entry.response.status) && locationHeader) {
|
|
|
|
|
const locationURL = new URL(locationHeader.value, url);
|
|
|
|
|
url = locationURL.toString();
|
|
|
|
|
if ((entry.response.status === 301 || entry.response.status === 302) && method === 'POST' ||
|
|
|
|
|
entry.response.status === 303 && !['GET', 'HEAD'].includes(method)) {
|
|
|
|
|
// HTTP-redirect fetch step 13 (https://fetch.spec.whatwg.org/#http-redirect-fetch)
|
|
|
|
|
method = 'GET';
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dispose() {
|
|
|
|
|
this._zipFile?.close();
|
|
|
|
|
}
|
2021-12-10 02:21:17 +01:00
|
|
|
}
|
2022-06-21 01:41:53 +02:00
|
|
|
|
2022-06-22 21:16:29 +02:00
|
|
|
function countMatchingHeaders(harHeaders: har.Header[], headers: HeadersArray): number {
|
2022-06-21 01:41:53 +02:00
|
|
|
const set = new Set(headers.map(h => h.name.toLowerCase() + ':' + h.value));
|
|
|
|
|
let matches = 0;
|
|
|
|
|
for (const h of harHeaders) {
|
|
|
|
|
if (set.has(h.name.toLowerCase() + ':' + h.value))
|
|
|
|
|
++matches;
|
|
|
|
|
}
|
|
|
|
|
return matches;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-03 21:47:51 +01:00
|
|
|
export async function urlToWSEndpoint(progress: Progress|undefined, endpointURL: string): Promise<string> {
|
2022-09-27 22:05:06 +02:00
|
|
|
if (endpointURL.startsWith('ws'))
|
|
|
|
|
return endpointURL;
|
|
|
|
|
|
2022-11-03 21:47:51 +01:00
|
|
|
progress?.log(`<ws preparing> retrieving websocket url from ${endpointURL}`);
|
2022-09-27 22:05:06 +02:00
|
|
|
const fetchUrl = new URL(endpointURL);
|
|
|
|
|
if (!fetchUrl.pathname.endsWith('/'))
|
|
|
|
|
fetchUrl.pathname += '/';
|
|
|
|
|
fetchUrl.pathname += 'json';
|
|
|
|
|
const json = await fetchData({
|
|
|
|
|
url: fetchUrl.toString(),
|
|
|
|
|
method: 'GET',
|
2022-11-03 21:47:51 +01:00
|
|
|
timeout: progress?.timeUntilDeadline() ?? 30_000,
|
2022-09-27 22:05:06 +02:00
|
|
|
headers: { 'User-Agent': getUserAgent() },
|
|
|
|
|
}, async (params: HTTPRequestParams, response: http.IncomingMessage) => {
|
|
|
|
|
return new Error(`Unexpected status ${response.statusCode} when connecting to ${fetchUrl.toString()}.\n` +
|
|
|
|
|
`This does not look like a Playwright server, try connecting via ws://.`);
|
|
|
|
|
});
|
2022-11-03 21:47:51 +01:00
|
|
|
progress?.throwIfAborted();
|
2022-09-27 22:05:06 +02:00
|
|
|
|
|
|
|
|
const wsUrl = new URL(endpointURL);
|
|
|
|
|
let wsEndpointPath = JSON.parse(json).wsEndpointPath;
|
|
|
|
|
if (wsEndpointPath.startsWith('/'))
|
|
|
|
|
wsEndpointPath = wsEndpointPath.substring(1);
|
|
|
|
|
if (!wsUrl.pathname.endsWith('/'))
|
|
|
|
|
wsUrl.pathname += '/';
|
|
|
|
|
wsUrl.pathname += wsEndpointPath;
|
|
|
|
|
wsUrl.protocol = wsUrl.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
|
|
|
return wsUrl.toString();
|
|
|
|
|
}
|