self.port.removeListener() in a content script isn't functional

RESOLVED FIXED in 1.10

Status

Add-on SDK
General
RESOLVED FIXED
6 years ago
5 years ago

People

(Reporter: Wladimir Palant (for Adblock Plus info Cc bugzilla@adblockplus.org), Unassigned)

Tracking

unspecified
1.10

Firefox Tracking Flags

(Not tracked)

Details

(URL)

Attachments

(1 attachment)

It seems that self.port.removeListener() isn't working at all in content scripts, self.port.once() isn't working properly either for that reason. The bug in is this line api-utils/lib/content/content-worker.js:

        let index = listeners[name].indexOf(name);

This should search the callback, not the event type:

        let index = listeners[name].indexOf(callback);

With this change things work properly.

Updated

6 years ago
Duplicate of this bug: 788964
Created attachment 658964 [details] [diff] [review]
s/name/callback/

All tests seem to pass with this change applied.
Attachment #658964 - Flags: review?(poirot.alex)
Comment on attachment 658964 [details] [diff] [review]
s/name/callback/

Thanks for the patch :)
Attachment #658964 - Flags: review?(poirot.alex) → review+

Comment 4

6 years ago
Commit pushed to master at https://github.com/mozilla/addon-sdk

https://github.com/mozilla/addon-sdk/commit/2190a6471c9b65fd5d1c2b9d71b6ec9c89d7dfe3
Bug 788981:  self.port.removeListener() in a content script isn't functional r=@ochameau
Wes, I don't think it would justify spinning another rc, but in case we do, it would be worth shipping that into 1.10.
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → 1.11
(In reply to Alexandre Poirot (:ochameau) from comment #5)
> Wes, I don't think it would justify spinning another rc, but in case we do,
> it would be worth shipping that into 1.10.

I think Will was wanting to get some doc changes into 1.10, so if he gets those in before we need to make the final call for 1.10, I'll pull this in, too.
+1 for putting this in 1.10.

Comment 8

6 years ago
Commit pushed to stabilization at https://github.com/mozilla/addon-sdk

https://github.com/mozilla/addon-sdk/commit/5703e32f2e1b4de7fd88b34473f6d0d9c13176ca
Bug 788981:  self.port.removeListener() in a content script isn't functional r=@ochameau
(cherry picked from commit 2190a6471c9b65fd5d1c2b9d71b6ec9c89d7dfe3)

Updated

6 years ago
Target Milestone: 1.11 → 1.10

Comment 9

5 years ago
The fix is probably correct, but self.port.removeListener() is still not functional when a different listener is reassigned afterwards: In this case the old ("removed") listener is magically reproduced and executed.

Created new bug 844433 for this to let this here sleep. Just wanted to mention it.
You need to log in before you can comment on or make changes to this bug.