Skip to content

Commit 19371ff

Browse files
author
Timothy Johnson
committed
Fixes #13 (again)
1 parent ad83ba0 commit 19371ff

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

dest/background.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function attachScript(tabId, changed) {
5555

5656
toolsPorts.get(tabId).postMessage({ type: 'init' })
5757
chrome.tabs.executeScript(tabId, {
58-
code: `const profilerEnabled = ${profilerEnabledList.includes(tabId)}`,
58+
code: `window.profilerEnabled = ${profilerEnabledList.includes(tabId)}`,
5959
runAt: 'document_start'
6060
})
6161
chrome.tabs.executeScript(tabId, {
@@ -69,7 +69,7 @@ function setup(tabId, port) {
6969
port.onDisconnect.addListener(() => {
7070
toolsPorts.delete(tabId)
7171
pagePorts.delete(tabId)
72-
const i = profilerEnabledList.indexOf(msg.tabId)
72+
const i = profilerEnabledList.indexOf(tabId)
7373
if (i != -1) profilerEnabledList.slice(i, 1)
7474
chrome.tabs.onUpdated.removeListener(attachScript)
7575
})

rollup.config.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,20 @@ export default [{
3636
file: 'dest/privilegedContent.js',
3737
name: 'SvelteDevtools',
3838
format: 'iife',
39-
banner: `const tag = document.createElement('script')
40-
tag.text = \``,
39+
banner: `if (!window.tag) {
40+
window.tag = document.createElement('script')
41+
window.tag.text = \``,
4142
footer: `\`
42-
if (profilerEnabled) tag.text = tag.text.replace('let profilerEnabled = false;', '\$&\\nstartProfiler();')
43-
document.children[0].append(tag)
44-
const port = chrome.runtime.connect()
45-
port.onMessage.addListener(window.postMessage.bind(window))
46-
window.addEventListener(
47-
'message',
48-
e => e.source == window && port.postMessage(e.data),
49-
false
50-
)`
43+
if (window.profilerEnabled) window.tag.text = window.tag.text.replace('let profilerEnabled = false;', '\$&\\nstartProfiler();')
44+
document.children[0].append(window.tag)
45+
const port = chrome.runtime.connect()
46+
port.onMessage.addListener(window.postMessage.bind(window))
47+
window.addEventListener(
48+
'message',
49+
e => e.source == window && port.postMessage(e.data),
50+
false
51+
)
52+
}`
5153
},
5254
plugins: [ resolve() ]
5355
}, {

0 commit comments

Comments
 (0)