Bug 156730 - MediaQueryList.addListener does not support Object with handleEvent() method
Summary: MediaQueryList.addListener does not support Object with handleEvent() method
Status: RESOLVED DUPLICATE of bug 203288
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
Depends on:
Reported: 2016-04-18 22:18 PDT by nkronlage
Modified: 2020-04-03 09:41 PDT (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description nkronlage 2016-04-18 22:18:56 PDT

    var query = matchMedia("(min-width: 400px)");

    var listener = {
      handleEvent: function() {
        document.body.style.background = query.matches ? 'red' : 'blue';


Runnable:  https://jsfiddle.net/j4278otv/

Running this results in the error: "[Error] TypeError: Argument 1 ('listener') to MediaQueryList.addListener must be a function"

The spec (https://drafts.csswg.org/cssom-view/#mediaquerylist) says the parameter to addListener is an EventListener (https://dom.spec.whatwg.org/#callbackdef-eventlistener): 

    callback interface EventListener {
      void handleEvent(Event event);

but the implementation only allows functions.

The Node.addEventListener method does support the Object with handleEvent() method:  See https://jsfiddle.net/6nL0epf3/
Comment 1 Alexey Shvayka 2020-04-03 09:41:56 PDT

*** This bug has been marked as a duplicate of bug 203288 ***