Closed Bug 1431568 Opened 7 years ago Closed 7 years ago

WebExtensions: Dead object exception when trying to access bg object from popup

Categories

(WebExtensions :: Untriaged, defect)

57 Branch
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: andry.virvich, Unassigned)

Details

(Keywords: testcase)

Attachments

(1 file)

46.07 KB, application/x-zip-compressed
Details
Attached file extension.zip
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 Steps to reproduce: I have an extension with a popup; There's a Backbone's view on it which should listen Model's changes from background and re-render itself popup: ```` var app = browser.extension.getBackgroundPage().app; var AppView = Backbone.View.extend({ el: 'body', template: function() { return `<h1>App View: ${this.model.get('time')}</h1>`; }, initialize: function() { this.listenTo(this.model, 'change', this.render); window.addEventListener('unload', () => { this.remove(); }); }, render: function() { this.$el.html(this.template()); } }); window.addEventListener('DOMContentLoaded', () => { new AppView({ model: app }).render(); }); ```` background: ```` var AppModel = Backbone.Model.extend({ initialize: function() { window.setInterval(() => { this.set({ time: +(new Date()) }); }, 1000); } }); window.app = new AppModel(); ```` (source code attached) Actual results: Everything works perfectly when I open popup for the first time When I try to open it again nothing happens and error in console appears: `TypeError: can't access dead object` Expected results: This works well without any errors in older Firefox versions (<57) Also works fine in Chrome
Component: Untriaged → Extension Compatibility
Summary: Dead object exception when trying to access bg object from popup → WebExtensions: Dead object exception when trying to access bg object from popup
Component: Extension Compatibility → WebExtensions: Untriaged
Keywords: testcase
Product: Firefox → Toolkit
This means that you're leaving references to objects from the closed popup in your background page. That's something we intentionally don't support for extension pages, since it's a common cause of serious leaks. When an extension page closes, all references to objects belonging to it become invalid.
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Resolution: --- → WONTFIX
(In reply to Kris Maglione [:kmag] (long backlog; ping on IRC if you're blocked) from comment #1) > This means that you're leaving references to objects from the closed popup > in your background page. That's something we intentionally don't support for > extension pages, since it's a common cause of serious leaks. When an > extension page closes, all references to objects belonging to it become > invalid. I checked backbone's code - looks like it stores all the references in _listeners object in background; When we remove view from popup it removes references from that object (so everything should be clean), however entire _listeners becomes 'dead'
(In reply to Andrey Vyrvich from comment #2) > I checked backbone's code - looks like it stores all the references in > _listeners object in background; When we remove view from popup it removes > references from that object (so everything should be clean), however entire > _listeners becomes 'dead' Yup, that's not surprising. You're loading two separate copies of Backbone, one in the popup, one in the background page. You're attaching an AppView created using the copy in the popup to the AppModel instance created by the copy in the background page. The _listeners object is created the first time it's necessary, and since it winds up being created by the Backbone copy loaded into the popup, the object itself also belongs to the popup, and can't outlive it.
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: