Skip to content

Commit

Permalink
Fixes dev tools inspect element functionality
Browse files Browse the repository at this point in the history
Resolves brave#10249

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed Aug 25, 2017
1 parent f4b456a commit 9b20fd1
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 15 deletions.
5 changes: 5 additions & 0 deletions app/browser/reducers/tabsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ const tabsReducer = (state, action, immutableAction) => {
tabs.toggleDevTools(action.get('tabId'))
})
break
case appConstants.APP_INSPECT_ELEMENT:
setImmediate(() => {
tabs.inspectElement(action.get('tabId'), action.get('x'), action.get('y'))
})
break
case appConstants.APP_LOAD_URL_REQUESTED:
setImmediate(() => {
tabs.loadURL(action)
Expand Down
7 changes: 7 additions & 0 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,13 @@ const api = {
}
},

inspectElement: (tabId, x, y) => {
const tab = getWebContents(tabId)
if (tab && !tab.isDestroyed()) {
tab.inspectElement(x, y)
}
},

setActive: (tabId) => {
let tab = getWebContents(tabId)
if (tab && !tab.isDestroyed()) {
Expand Down
15 changes: 15 additions & 0 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,21 @@ const appActions = {
})
},

/**
* Dispatches a message to inspect desired element on the page
* @param {number} tabId - The tabId
* @param {number} x - horizontal position of the element
* @param {number} y - vertical position of the element
*/
inspectElement: function (tabId, x, y) {
dispatch({
actionType: appConstants.APP_INSPECT_ELEMENT,
tabId,
x,
y
})
},

/**
* Dispatches a message when a tab is being cloned
* @param {number} tabId - The tabId of the tab to clone
Expand Down
12 changes: 0 additions & 12 deletions js/actions/webviewActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ const webviewActions = {
}
},

/**
* Inspect the element for the active webview at the x, y content position
* @param {number} x - horizontal position of the element to inspect
* @param {number} y - vertical position of the element to inspect
*/
inspectElement: function (x, y) {
const webview = getWebview()
if (webview) {
webview.inspectElement(x, y)
}
},

/**
* Shows the certificate infomation
*/
Expand Down
3 changes: 2 additions & 1 deletion js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ const appConstants = {
APP_REMOVE_BOOKMARK_FOLDER: _,
APP_REMOVE_BOOKMARK: _,
APP_MOVE_BOOKMARK_FOLDER: _,
APP_MOVE_BOOKMARK: _
APP_MOVE_BOOKMARK: _,
APP_INSPECT_ELEMENT: _
}

module.exports = mapValuesByKeys(appConstants)
4 changes: 2 additions & 2 deletions js/contextMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -1154,8 +1154,8 @@ function mainTemplateInit (nodeProps, frame, tab) {
if (!isAboutPage) {
template.push({
label: locale.translation('inspectElement'),
click: (item) => {
webviewActions.inspectElement(nodeProps.x, nodeProps.y)
click: () => {
appActions.inspectElement(frame.get('tabId'), nodeProps.x, nodeProps.y)
}
})
}
Expand Down

0 comments on commit 9b20fd1

Please sign in to comment.