UNPKG

@dcloudio/uni-debugger

Version:

uni-app debugger

34 lines (31 loc) 797 B
const opn = require('chrome-opn') const pendingList = [] let pending = false const launchChrome = function (url, remoteDebugPort, wait, callback) { if (!pending) { pending = true url = url.replace(/[&*]/g, '\\&') const args = remoteDebugPort > 0 ? ['-remote-debugging-port=' + remoteDebugPort] : null opn(url, args, !!wait).then(cp => { cp.once('close', e => { callback && callback(null) if (pendingList.length > 0) { pending = false pendingList.shift()() } }) cp.once('error', err => { pending = false callback && callback(err) }) }) } else { pendingList.push(function () { launchChrome(url, remoteDebugPort, wait, callback) }) } } module.exports = { launchChrome }