On my chrome extension I'm trying to listen to logs that were output from any tab.
On my content-script.js
I have
import browser from 'webextension-polyfill'
console.defaultLog = console.log.bind(console)
console.log = function () {
console.defaultLog.apply(console, arguments)
browser.runtime.sendMessage({
name: 'registerLog',
payload: { log: Array.from(arguments) }
})
}
In my background.ts
I have:
import browser from 'webextension-polyfill'
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
console.log(request)
})
Then, I created an extremely simple page test.html
where it just has a setInterval
using console.log
:
<html>
<script>
setInterval(() => console.log('from page test'), 1000)
</script>
</html>
I can see the from page test
log in my test.html
but I can't see the log in my service work extension.
Is it possible to listen to console.log
s from pages in a chrome extension? If yes, what am I doing wrong?