Skip to content

Commit

Permalink
fix: pass result to chrome.tabs.executeScript callback (backport: 5-0…
Browse files Browse the repository at this point in the history
…-x) (#16949)

* fix: pass result to chrome.tabs.executeScript callback

Additionally, remove `nextId` counter in favor of `originResultID` counter which is more widely used in this file.

* fix: remove need for eslint override and better match style
  • Loading branch information
trop[bot] authored and John Kleinschmidt committed Feb 14, 2019
1 parent 25e6eb9 commit cc9c84c
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions lib/renderer/chrome-api.js
Expand Up @@ -4,8 +4,6 @@ const ipcRenderer = require('@electron/internal/renderer/ipc-renderer-internal')
const Event = require('@electron/internal/renderer/extensions/event')
const url = require('url')

let nextId = 0

class Tab {
constructor (tabId) {
this.id = tabId
Expand Down Expand Up @@ -146,14 +144,12 @@ exports.injectTo = function (extensionId, isBackgroundPage, context) {
}

chrome.tabs = {
executeScript (tabId, details, callback) {
const requestId = ++nextId
ipcRenderer.once(`CHROME_TABS_EXECUTESCRIPT_RESULT_${requestId}`, (event, result) => {
// Disabled due to false positive in StandardJS
// eslint-disable-next-line standard/no-callback-literal
callback([event.result])
})
ipcRenderer.send('CHROME_TABS_EXECUTESCRIPT', requestId, tabId, extensionId, details)
executeScript (tabId, details, resultCallback) {
if (resultCallback) {
ipcRenderer.once(`CHROME_TABS_EXECUTESCRIPT_RESULT_${originResultID}`, (event, result) => resultCallback([result]))
}
ipcRenderer.send('CHROME_TABS_EXECUTESCRIPT', originResultID, tabId, extensionId, details)
originResultID++
},

sendMessage (tabId, message, options, responseCallback) {
Expand Down

0 comments on commit cc9c84c

Please sign in to comment.