Skip to content

Commit

Permalink
fix: catching error when no available web pages (#1031)
Browse files Browse the repository at this point in the history
* fix: catching error when no available web pages

* set [] by default

* define local func
  • Loading branch information
KazuCocoa committed Aug 7, 2019
1 parent a20c098 commit ba4e79f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/commands/context.js
Expand Up @@ -155,10 +155,19 @@ extensions.listWebFrames = async function listWebFrames (useUrl = true) {
log.debug(`Selecting by url: ${useUrl} ${useUrl ? `(expected url: '${this.getCurrentUrl()}')` : ''}`);

const currentUrl = useUrl ? this.getCurrentUrl() : undefined;
let pageArray;
let pageArray = [];
const getWebviewPages = async () => {
try {
return await this.remote.selectApp(currentUrl, this.opts.webviewConnectRetries, this.opts.ignoreAboutBlankUrl);
} catch (err) {
log.debug(`No available web pages: ${err.message}`);
return [];
}
};

if (this.remote && this.remote.appIdKey) {
// already connected
pageArray = await this.remote.selectApp(currentUrl, this.opts.webviewConnectRetries, this.opts.ignoreAboutBlankUrl);
pageArray = await getWebviewPages();
} else {
// not connected
this.remote = await this.getNewRemoteDebugger();
Expand All @@ -168,7 +177,7 @@ extensions.listWebFrames = async function listWebFrames (useUrl = true) {
log.debug('Unable to connect to the remote debugger.');
return [];
}
pageArray = await this.remote.selectApp(currentUrl, this.opts.webviewConnectRetries, this.opts.ignoreAboutBlankUrl);
pageArray = await getWebviewPages();
this.remote.on(RemoteDebugger.EVENT_PAGE_CHANGE, this.onPageChange.bind(this));
this.remote.on(RemoteDebugger.EVENT_FRAMES_DETACHED, () => {
if (!_.isEmpty(this.curWebFrames)) {
Expand Down

0 comments on commit ba4e79f

Please sign in to comment.