https://github.com/jeremyben/webpack-webextension-background-logger
Centralize console logs in background page (web/chrome extensions)
https://github.com/jeremyben/webpack-webextension-background-logger
chrome-extension log-centralization webpack
Last synced: 9 months ago
JSON representation
Centralize console logs in background page (web/chrome extensions)
- Host: GitHub
- URL: https://github.com/jeremyben/webpack-webextension-background-logger
- Owner: jeremyben
- License: mit
- Created: 2019-01-17T20:32:18.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-05-30T20:09:21.000Z (about 6 years ago)
- Last Synced: 2024-12-12T03:06:04.213Z (over 1 year ago)
- Topics: chrome-extension, log-centralization, webpack
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/webpack-webextension-background-logger
- Size: 68.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
# Web Extension Background Logger
## What
**Log centralization** for you Web/Chrome Extension.
Compatible with every browser extension : **Chrome**, **Firefox**, **Safari**, **Edge**.
## Why
When you develop your Web Extension, you have to keep an eye on multiple consoles and logs from :
- Background script.
- Content script.
- Popup page (either _page action_ or _browser action_).
- Option page.
This webpack plugin allows you to centralize all logs in the background page console.
## Get Started
First, install Web Extension Background Logger :
```bash
# npm
npm i -D webpack-webextension-background-logger
# yarn
yarn add -D webpack-webextension-background-logger
```
Add to your Webpack config :
```js
const BackgroundLogger = require('webpack-webextension-background-logger')
module.exports = {
// your webpack config
// ...
plugins: [new BackgroundLogger()],
}
```
Web Extension Background Logger will look for an entry named `background` by default, but you can customize this :
```js
new BackgroundLogger({ backgroundEntry: 'main' })
```
## Usage
Now, instead of using good old `console.log`, simply use `console.bg` :
```js
console.bg('loggy-log-log', foo)
```
This will print your log in the background page console.
#### Types for `console.bg`
If you use TypeScript, or type check your JavaScript (like this project does), you might want to tell the compiler that `console.bg` exists.
To do this, include in a declaration file (`typings.d.ts` for example) at the root of your project :
```ts
///
```
Or you can add to your `tsonfig.json` :
```json
{
"compilerOptions": {
"typeRoots": ["node_modules/@types", "node_modules/webpack-webextension-background-logger"]
}
}
```
### Production build
For production builds, you can opt out of background logger and revert to plain `console.log` statements :
```js
new BackgroundLogger({ revertToLog: true })
```
This will simply remove Background Logger from your build and rewrite every `console.bg` statement into `console.log` statement.