Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
useUrl = useUrl && !!this.getCurrentUrl();
logger.debug(`Selecting by url: ${useUrl} ${useUrl ? `(expected url: '${this.getCurrentUrl()}')` : ''}`);
let currentUrl = useUrl ? this.getCurrentUrl() : undefined;
let pageArray;
if (this.isRealDevice() && this.remote && this.opts.bundleId) {
// real device, and already connected
pageArray = await this.remote.pageArrayFromJson(this.opts.ignoreAboutBlankUrl);
} else if (this.remote && this.remote.appIdKey) {
// simulator, and already connected
pageArray = await this.remote.selectApp(currentUrl, this.opts.webviewConnectRetries, this.opts.ignoreAboutBlankUrl);
} else if (this.isRealDevice()) {
// real device, and not connected
try {
this.remote = new WebKitRemoteDebugger({
port: this.opts.webkitDebugProxyPort,
webkitResponseTimeout: this.opts.webkitResponseTimeout,
platformVersion: this.opts.platformVersion,
isSafari: this.isSafari(),
garbageCollectOnExecute: false,
logFullResponse: !!this.opts.safariShowFullResponse,
});
pageArray = await this.remote.pageArrayFromJson(this.opts.ignoreAboutBlankUrl);
} catch (err) {
// it is reasonable to expect that this might be called when there is no
// webkit remote debugger to connect to
if (!_.includes(err.message, 'connect ECONNREFUSED')) throw err; // eslint-disable-line curly
logger.warn('Attempted to get a list of webview contexts but could not connect to ' +
'ios-webkit-debug-proxy. If you expect to find webviews, please ensure ' +
'that the proxy is running and accessible');