Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable console in contentscript #10040

Merged
merged 6 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/manifest/_base.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
{
"matches": ["file://*/*", "http://*/*", "https://*/*"],
"js": [
"disable-console.js",
"globalthis.js",
"lockdown.js",
"runLockdown.js",
Expand Down
10 changes: 5 additions & 5 deletions app/scripts/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ function injectScript(content) {
scriptTag.textContent = content
container.insertBefore(scriptTag, container.children[0])
container.removeChild(scriptTag)
} catch (e) {
console.error('MetaMask provider injection failed.', e)
} catch (error) {
console.error('MetaMask: Provider injection failed.', error)
}
}

Expand Down Expand Up @@ -85,7 +85,7 @@ function forwardTrafficBetweenMuxes(channelName, muxA, muxB) {
const channelB = muxB.createStream(channelName)
pump(channelA, channelB, channelA, (error) =>
console.debug(
`MetaMask muxed traffic for channel "${channelName}" failed.`,
`MetaMask: Muxed traffic for channel "${channelName}" failed.`,
error,
),
)
Expand All @@ -99,7 +99,7 @@ function forwardTrafficBetweenMuxes(channelName, muxA, muxB) {
*/
function logStreamDisconnectWarning(remoteLabel, error) {
console.debug(
`MetaMask Contentscript: Lost connection to "${remoteLabel}".`,
`MetaMask: Content script lost connection to "${remoteLabel}".`,
error,
)
}
Expand Down Expand Up @@ -223,7 +223,7 @@ function blockedDomainCheck() {
* Redirects the current page to a phishing information page
*/
function redirectToPhishingWarning() {
console.log('MetaMask - routing to Phishing Warning component')
Gudahtt marked this conversation as resolved.
Show resolved Hide resolved
console.debug('MetaMask: Routing to Phishing Warning component.')
const extensionURL = extension.runtime.getURL('phishing.html')
window.location.href = `${extensionURL}#${querystring.stringify({
hostname: window.location.hostname,
Expand Down
9 changes: 9 additions & 0 deletions app/scripts/disable-console.js
Original file line number Diff line number Diff line change
@@ -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
}
18 changes: 18 additions & 0 deletions development/build/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,20 @@ function createScriptTasks({ browserPlatforms, livereload }) {
}),
)
})

// inpage must be built before contentscript
// because inpage bundle result is included inside contentscript
const contentscriptSubtask = createTask(
`${taskPrefix}:contentscript`,
createTaskForBuildJsExtensionContentscript({ devMode, testing }),
)

// this can run whenever
const disableConsoleSubtask = createTask(
`${taskPrefix}:disable-console`,
createTaskForBuildJsExtensionDisableConsole({ devMode }),
)

// task for initiating livereload
const initiateLiveReload = async () => {
if (devMode) {
Expand All @@ -142,6 +149,7 @@ function createScriptTasks({ browserPlatforms, livereload }) {
const allSubtasks = [
...standardSubtasks,
contentscriptSubtask,
disableConsoleSubtask,
].map((subtask) => runInChildProcess(subtask))
// const allSubtasks = [...standardSubtasks, contentscriptSubtask].map(subtask => (subtask))
// make a parent task that runs each task in a child thread
Expand All @@ -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 }) {
const inpage = 'inpage'
const contentscript = 'contentscript'
Expand Down