Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
open background page devtools when navigating to background page url
Browse files Browse the repository at this point in the history
  • Loading branch information
bridiver committed Mar 26, 2017
1 parent 396cdbc commit 47793ab
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 10 deletions.
9 changes: 9 additions & 0 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ const api = {
return
}

if (newTab.isBackgroundPage()) {
if (newTab.isDevToolsOpened()) {
newTab.devToolsWebContents.focus()
} else {
newTab.openDevTools()
}
return
}

let location = newTab.getURL()
if (!location || location === '') {
location = 'about:blank'
Expand Down
7 changes: 7 additions & 0 deletions app/common/lib/httpUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ module.exports.isFrameError = function (errorCode) {
return errorCode >= 100 && errorCode <= 899
}

module.exports.isAborted = function (errorCode) {
errorCode = Math.abs(errorCode)
return errorCode === 3
}

/**
* Gets the l10n id for the chrome error code
* @param {number} errorCode the error code
Expand Down Expand Up @@ -56,6 +61,8 @@ module.exports.l10nErrorText = function (errorCode) {
}

module.exports.errorMap = {
// An operation was aborted (due to user action).
3: 'aborted',
// A connection was reset (corresponding to a TCP RST).
101: 'connectionReset',
// A connection attempt was refused.
Expand Down
42 changes: 33 additions & 9 deletions app/renderer/reducers/urlBarReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,22 @@
const windowConstants = require('../../../js/constants/windowConstants')
const {getSourceAboutUrl, getSourceMagnetUrl, isIntermediateAboutPage, navigatableTypes} = require('../../../js/lib/appUrlUtil')
const {isURL, getUrlFromInput} = require('../../../js/lib/urlutil')
const {activeFrameStatePath, frameStatePath, getFrameByKey, getActiveFrame, tabStatePath} = require('../../../js/state/frameStateUtil')
const {activeFrameStatePath, frameStatePath, frameStatePathForFrame, getFrameByKey, getActiveFrame, tabStatePath, getFrameByTabId} = require('../../../js/state/frameStateUtil')
const urlParse = require('../../common/urlParse')

const getLocation = (location) => {
location = location.trim()
location = getSourceAboutUrl(location) ||
getSourceMagnetUrl(location) ||
location

if (isURL(location)) {
location = getUrlFromInput(location)
}

return location
}

const updateNavBarInput = (state, loc, framePath) => {
if (framePath === undefined) {
framePath = activeFrameStatePath(state)
Expand All @@ -18,6 +31,21 @@ const updateNavBarInput = (state, loc, framePath) => {
return state
}

const navigationAborted = (state, action) => {
const frame = getFrameByTabId(state, action.tabId)
if (frame) {
let location = action.location || frame.get('provisionalLocation')
if (location) {
location = getLocation(location)
state = updateNavBarInput(state, location)
state = state.mergeIn(frameStatePathForFrame(state, frame), {
location
})
}
}
return state
}

const urlBarReducer = (state, action) => {
switch (action.actionType) {
case windowConstants.WINDOW_SET_NAVBAR_INPUT:
Expand Down Expand Up @@ -72,16 +100,9 @@ const urlBarReducer = (state, action) => {
}
break
case windowConstants.WINDOW_SET_NAVIGATED:
action.location = action.location.trim()
// For about: URLs, make sure we store the URL as about:something
// and not what we map to.
action.location = getSourceAboutUrl(action.location) ||
getSourceMagnetUrl(action.location) ||
action.location

if (isURL(action.location)) {
action.location = getUrlFromInput(action.location)
}
action.location = getLocation(action.location)

const key = action.key || state.get('activeFrameKey')
state = state.mergeIn(frameStatePath(state, key), {
Expand Down Expand Up @@ -122,6 +143,9 @@ const urlBarReducer = (state, action) => {
state = updateNavBarInput(state, action.location, frameStatePath(state, key))
}
break
case windowConstants.WINDOW_SET_NAVIGATION_ABORTED:
state = navigationAborted(state, action)
break
}
return state
}
Expand Down
12 changes: 12 additions & 0 deletions docs/windowActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ Dispatches a message to the store to let it know a page has been navigated.



### navigationAborted(tabId, location)

Dispatches a message to the store to let it know the page navigation was aborted

**Parameters**

**tabId**: `number`, Dispatches a message to the store to let it know the page navigation was aborted

**location**: `string`, the last committed location if available



### setSecurityState(frameProps, securityState)

Dispatches a message to set the security state.
Expand Down
14 changes: 14 additions & 0 deletions js/actions/windowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ const windowActions = {
})
},

/**
* Dispatches a message to the store to let it know the page navigation was aborted
*
* @param {number} tabId
* @param {string} location the last committed location if available
*/
navigationAborted: function (tabId, location) {
dispatch({
actionType: windowConstants.WINDOW_SET_NAVIGATION_ABORTED,
tabId,
location
})
},

/**
* Dispatches a message to set the security state.
* @param {Object} frameProps - The frame properties to modify.
Expand Down
5 changes: 4 additions & 1 deletion js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const getSetting = require('../settings').getSetting
const config = require('../constants/config')
const settings = require('../constants/settings')
const {aboutUrls, isSourceMagnetUrl, isSourceAboutUrl, isTargetAboutUrl, getTargetAboutUrl, getBaseUrl, isIntermediateAboutPage} = require('../lib/appUrlUtil')
const {isFrameError} = require('../../app/common/lib/httpUtil')
const {isFrameError, isAborted} = require('../../app/common/lib/httpUtil')
const locale = require('../l10n')
const appConfig = require('../constants/appConfig')
const {getSiteSettingsForHostPattern} = require('../state/siteSettings')
Expand Down Expand Up @@ -881,6 +881,9 @@ class Frame extends ImmutableComponent {
})
windowActions.loadUrl(this.frame, 'about:error')
appActions.removeSite(siteUtil.getDetailFromFrame(this.frame))
} else if (isAborted(e.errorCode)) {
// just stay put
windowActions.navigationAborted(this.frame.get('tabId'), url)
} else if (provisionLoadFailure) {
windowActions.setNavigated(url, this.props.frameKey, true, this.frame.get('tabId'))
}
Expand Down
1 change: 1 addition & 0 deletions js/constants/windowConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const windowConstants = {
WINDOW_SET_FRAME_TAB_ID: _,
WINDOW_SET_FRAME_TITLE: _,
WINDOW_SET_NAVIGATED: _,
WINDOW_SET_NAVIGATION_ABORTED: _,
WINDOW_SET_URL_BAR_ACTIVE: _, // whether the URL bar is being typed in
WINDOW_UNDO_CLOSED_FRAME: _,
WINDOW_CLEAR_CLOSED_FRAMES: _,
Expand Down

0 comments on commit 47793ab

Please sign in to comment.