Closed Bug 1336759 Opened 8 years ago Closed 8 years ago

notifications.create does not handle unsupported options gracefully

Categories

(WebExtensions :: Compatibility, defect)

52 Branch
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1250223

People

(Reporter: 4mr.minj, Unassigned)

Details

I have some code to the effect of > Promise.resolve().then(function() { > browser.notifications.create(gId, options) > .then((...args) => { > console.log('hi', args); > }, (...args) => { > console.log('yuck', args); > }); > }).catch((...args)=>console.log('uncaught', args)); when |options| contains a |buttons| property Firefox complains that is not supported[1] (missing documentation[2] btw). However the way that is done is ungraceful (dis-? :P). Rather than rejecting the promise ('yuck'), a synchronous exception is thrown (caught at 'uncaught'). Similarly, the callback/chrome.extension.lastError mechanism is not used in this case: > Promise.resolve().then(function() { > chrome.notifications.create(gId, options, > function(nId) { > var err = chrome.runtime.lastError; > if (err) { > if (/^Adding buttons/.test(err.message)) { > // opera does not support buttons > return; > } > } > else { > chrome.notifications.onClicked.addListener(onClicked); > chrome.notifications.onButtonClicked.addListener(onButtonClicked); > chrome.notifications.onClosed.addListener(onClosed); > } > }); > }).catch((...args) => console.log('uncaught', args)); By the way, if case you are curious, I am testing for a specific Error message on Opera here[3], but I guess identical error messages would be too much to ask. Tested on FF52 (aurora build) [1] "Type error for parameter options (Property "buttons" is unsupported by Firefox) for notifications.create." [2] https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/notifications/create [3] "Adding buttons to notifications is not supported."
(In reply to Mindaugas <LA-MJ> from comment #0) > By the way, if case you are curious, I am testing for a specific Error > message on Opera here[3], but I guess identical error messages would be too > much to ask. The contents of the message property of Error has never been something stable or portable. The rest of this is covered in the duplicate below though we've had the current behavior for long enough now that it may be tough to change it.
Status: UNCONFIRMED → RESOLVED
Closed: 8 years ago
Resolution: --- → DUPLICATE
Does it really? I stumbled upon this using the callback version (since that's what chrome/opera needs), and the dupe does not mention callbacks. I guess I'll add a comment there.
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.