mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
Disable console in contentscript (#10040)
* Maintain console logging in dev mode Co-authored-by: kumavis <aaron@kumavis.me> Co-authored-by: Erik Marks <rekmarks@protonmail.com> Co-authored-by: Mark Stacey <markjstacey@gmail.com>
This commit is contained in:
parent
9a1548368f
commit
69df19f195
@ -38,6 +38,7 @@
|
|||||||
{
|
{
|
||||||
"matches": ["file://*/*", "http://*/*", "https://*/*"],
|
"matches": ["file://*/*", "http://*/*", "https://*/*"],
|
||||||
"js": [
|
"js": [
|
||||||
|
"disable-console.js",
|
||||||
"globalthis.js",
|
"globalthis.js",
|
||||||
"lockdown.js",
|
"lockdown.js",
|
||||||
"runLockdown.js",
|
"runLockdown.js",
|
||||||
|
@ -38,8 +38,8 @@ function injectScript(content) {
|
|||||||
scriptTag.textContent = content
|
scriptTag.textContent = content
|
||||||
container.insertBefore(scriptTag, container.children[0])
|
container.insertBefore(scriptTag, container.children[0])
|
||||||
container.removeChild(scriptTag)
|
container.removeChild(scriptTag)
|
||||||
} catch (e) {
|
} catch (error) {
|
||||||
console.error('MetaMask provider injection failed.', e)
|
console.error('MetaMask: Provider injection failed.', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ function forwardTrafficBetweenMuxes(channelName, muxA, muxB) {
|
|||||||
const channelB = muxB.createStream(channelName)
|
const channelB = muxB.createStream(channelName)
|
||||||
pump(channelA, channelB, channelA, (error) =>
|
pump(channelA, channelB, channelA, (error) =>
|
||||||
console.debug(
|
console.debug(
|
||||||
`MetaMask muxed traffic for channel "${channelName}" failed.`,
|
`MetaMask: Muxed traffic for channel "${channelName}" failed.`,
|
||||||
error,
|
error,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -99,7 +99,7 @@ function forwardTrafficBetweenMuxes(channelName, muxA, muxB) {
|
|||||||
*/
|
*/
|
||||||
function logStreamDisconnectWarning(remoteLabel, error) {
|
function logStreamDisconnectWarning(remoteLabel, error) {
|
||||||
console.debug(
|
console.debug(
|
||||||
`MetaMask Contentscript: Lost connection to "${remoteLabel}".`,
|
`MetaMask: Content script lost connection to "${remoteLabel}".`,
|
||||||
error,
|
error,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -223,7 +223,7 @@ function blockedDomainCheck() {
|
|||||||
* Redirects the current page to a phishing information page
|
* Redirects the current page to a phishing information page
|
||||||
*/
|
*/
|
||||||
function redirectToPhishingWarning() {
|
function redirectToPhishingWarning() {
|
||||||
console.log('MetaMask - routing to Phishing Warning component')
|
console.debug('MetaMask: Routing to Phishing Warning component.')
|
||||||
const extensionURL = extension.runtime.getURL('phishing.html')
|
const extensionURL = extension.runtime.getURL('phishing.html')
|
||||||
window.location.href = `${extensionURL}#${querystring.stringify({
|
window.location.href = `${extensionURL}#${querystring.stringify({
|
||||||
hostname: window.location.hostname,
|
hostname: window.location.hostname,
|
||||||
|
9
app/scripts/disable-console.js
Normal file
9
app/scripts/disable-console.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// Disable console.log in contentscript to prevent SES/lockdown logging to external page
|
||||||
|
// eslint-disable-next-line import/unambiguous
|
||||||
|
if (
|
||||||
|
!(typeof process !== 'undefined' && process.env.METAMASK_DEBUG) &&
|
||||||
|
typeof console !== undefined
|
||||||
|
) {
|
||||||
|
console.log = () => undefined
|
||||||
|
console.info = () => undefined
|
||||||
|
}
|
@ -115,6 +115,7 @@ function createScriptTasks({ browserPlatforms, livereload }) {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
// inpage must be built before contentscript
|
// inpage must be built before contentscript
|
||||||
// because inpage bundle result is included inside contentscript
|
// because inpage bundle result is included inside contentscript
|
||||||
const contentscriptSubtask = createTask(
|
const contentscriptSubtask = createTask(
|
||||||
@ -122,6 +123,12 @@ function createScriptTasks({ browserPlatforms, livereload }) {
|
|||||||
createTaskForBuildJsExtensionContentscript({ devMode, testing }),
|
createTaskForBuildJsExtensionContentscript({ devMode, testing }),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// this can run whenever
|
||||||
|
const disableConsoleSubtask = createTask(
|
||||||
|
`${taskPrefix}:disable-console`,
|
||||||
|
createTaskForBuildJsExtensionDisableConsole({ devMode }),
|
||||||
|
)
|
||||||
|
|
||||||
// task for initiating livereload
|
// task for initiating livereload
|
||||||
const initiateLiveReload = async () => {
|
const initiateLiveReload = async () => {
|
||||||
if (devMode) {
|
if (devMode) {
|
||||||
@ -142,6 +149,7 @@ function createScriptTasks({ browserPlatforms, livereload }) {
|
|||||||
const allSubtasks = [
|
const allSubtasks = [
|
||||||
...standardSubtasks,
|
...standardSubtasks,
|
||||||
contentscriptSubtask,
|
contentscriptSubtask,
|
||||||
|
disableConsoleSubtask,
|
||||||
].map((subtask) => runInChildProcess(subtask))
|
].map((subtask) => runInChildProcess(subtask))
|
||||||
// const allSubtasks = [...standardSubtasks, contentscriptSubtask].map(subtask => (subtask))
|
// const allSubtasks = [...standardSubtasks, contentscriptSubtask].map(subtask => (subtask))
|
||||||
// make a parent task that runs each task in a child thread
|
// make a parent task that runs each task in a child thread
|
||||||
@ -165,6 +173,16 @@ function createScriptTasks({ browserPlatforms, livereload }) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createTaskForBuildJsExtensionDisableConsole({ devMode }) {
|
||||||
|
const filename = 'disable-console'
|
||||||
|
return bundleTask({
|
||||||
|
label: filename,
|
||||||
|
filename: `${filename}.js`,
|
||||||
|
filepath: `./app/scripts/${filename}.js`,
|
||||||
|
devMode,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function createTaskForBuildJsExtensionContentscript({ devMode, testing }) {
|
function createTaskForBuildJsExtensionContentscript({ devMode, testing }) {
|
||||||
const inpage = 'inpage'
|
const inpage = 'inpage'
|
||||||
const contentscript = 'contentscript'
|
const contentscript = 'contentscript'
|
||||||
|
Loading…
Reference in New Issue
Block a user