user1829122
user1829122

Reputation: 61

How much memory should an "empty" Chrome extension be expected to use?

I've built a very simply chrome extension which simply opens a URL in a new tab when clicked (via a short JS function which uses the current URL of the page). It doesn't do anything in the background.

Is it normal for it to use around 20mb of memory? Can anything be done to reduce the amount of memory used?

This is the background.js code:

chrome.browserAction.onClicked.addListener(function(tab) {
    chrome.tabs.executeScript(tab.id, {file: "bookmarklet.js"})
});

Upvotes: 0

Views: 238

Answers (1)

Rob W
Rob W

Reputation: 348962

A light-weight Chrome extension typically uses 10-20 MB of memory.

That having said, I recommend to use the following manifest file to minimize memory usage and minimize the use of permissions:

{
    "name": "Name of your extension",
    "version": "1.0",
    "manifest_version": 2,
    "background": {
        "scripts": ["background.js"],
        "persistent": false
    },
    "browser_action": {
        "default_title": "Your badge title here (optional)",
        "default_icon": "icon19.png"
    },
    "permissions": [
        "activeTab"
    ],
    "minimum_chrome_version": "26"
}

If you wish, also add the icons and description fields to provide extra metadata.

By using "persistent": "false", you've turned your background page into an event page. Event pages only activate when needed, e.g. when your button is clicked. When not needed, the page is automatically unloaded, resulting in no memory usage.

I guess that you've used the "tabs" and "<all_urls>" or "*://*/*" permissions. For your use case, it suffices to drop these permissions and use activeTab instead, which grants the extension temporary access to a tab when the button is clicked. This feature is available since Chrome 26.

Upvotes: 2

Related Questions