error using Notification API on Dart - dart

I've used Notifications working on a JavaScript app and It's very useful when you don't have to be all the time looking at the app when something important needs to be acknowledged. I tried to replicate some work on Dart but a reference error is shown on compiled to JS Chrome.
Do you know if It's going to be implemented for Chrome soon? or is It going to remain experimental?
Thanks in advance
This is the function which tries to call Notification API. Without Notification line, everything works, when I add Notification line I get this error "Uncaught ReferenceError: requestPermission is not defined" running the code as JavaScript. (I am importing 'dart:html')
void revisarInput() {
if ( valorLogin != '' ) {
indicador = true;
_ws.send( Util.formatearJsonSocket( 'loginPwd', { 'pwd': int.parse( valorLogin )}));
}
Notification.requestPermission();
}

This was a bug in dart2js, https://code.google.com/p/dart/issues/detail?id=22483 and is fixed for Dart 1.9.

This page says
https://developer.chrome.com/apps/notifications
Stable since Chrome 28

Related

Electron app crashes on print ubuntu 20.04 Linux

It's been a week I am struggling with this problem. I've searched throughout the web and found many answers but none of them worked for me and also most of the topics relating to this problem are unsolved in various forums as well.
Whenever my application executes the following line of code from the main process it crashes :
win.webContents.print();
Following is the crash report:
'''
I've tried the option:
win.webContents.print({silent: true}, (success, error) => {
if(success) {
console.log("Printed...");
}else {
console.log(error);
}
});
'''
No matter what I do, I get the same crash report.
Furthermore, If I print from the console of the browser window, the same crash occurs,
'''
With the same error as shown below :
'''
I am very close to the deadline of a project in which I have to integrate a printing facility to the POS thermal receipt printer, and can not find any solutions.
Also, I've used other libraries like electron-pos-printer, But internally, it uses the same concept and codes for printing, and thus, this way also failed.
It's really frustrating... Need help !!!

Why is this this error: Failed to execute 'fetch' on 'ServiceWorkerGlobalScope': 'only-if-cached' can be set only with 'same-origin' mode [duplicate]

After upgrading to Chrome 64, I realized that this error appears when I load my page on a new tab.
I can't identify where it is on the service worker. Here is my code to run the fetch:
self.addEventListener('fetch', function(event) {
if (event.request.url.startsWith(self.location.origin)) {
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request).then(function(fetch_resp){
return fetch_resp;
});
})
);
}
});
Could anyone here, who has more knowledge about service worker, help me to solve this error?
I believe this is a Chromium bug that has been reported here. Hopefully it will be fixed soon or some more information about the issue will be published.
Paul Irish implemented a temporary work around, which is as follows:
if (e.request.cache === 'only-if-cached' && e.request.mode !== 'same-origin') {
return;
}
I ran it inside the callback for the service worker install and fetch listeners and it prevented the error.
You can see the full commit of Paul's code here.
For those searching for this again, seems like it popped up after a while again when someone opens the devtools you can still see the error mentioned in the question.
See (new) bug report here: https://bugs.chromium.org/p/chromium/issues/detail?id=1098389
So let's hope this will be fixed again soon!
perhaps the cache name is not unique from other applications, seems to fix the issue for me.

Call function in a dart polymer element [duplicate]

Having a weird issue. In my Dart code I have some polymer components on the screen and one of them has a method I call from my main().
I grab a reference to it by doing
PolyComp poly = querySelector("#idOfPolymer");
poly.flash();
This works perfectly in dart. The page loads up and PolyComp starts to flash. However when I run this in Chrome by running Build Polymer app from the Dart IDE, I get an error that says cannot call flash() on null.
I ended up making it flash by just using an event bus and letting PolyComp listen to my event, but this is overkill.
What am I doing wrong? This happens in the latest Chrome, Firefox and Safari.
Edit:
I built the following polymer app to JS also and ran into the same issue.
https://github.com/sethladd/dart-polymer-dart-examples/blob/master/web/todo_element/todo.html
Works on DartVM, not in Chrome because its calling a method on a null element.
When you run this code from the main() method it is probably a timing issue.
You can try something like
import "package:polymer/polymer.dart";
main() {
initPolymer().run(() {
// code here works most of the time
Polymer.onReady.then((e) {
// some things must wait until onReady callback is called
});
});
}
see also how to implement a main function in polymer apps

Polymer querySelector working on DartVM but not in Chrome after compile

Having a weird issue. In my Dart code I have some polymer components on the screen and one of them has a method I call from my main().
I grab a reference to it by doing
PolyComp poly = querySelector("#idOfPolymer");
poly.flash();
This works perfectly in dart. The page loads up and PolyComp starts to flash. However when I run this in Chrome by running Build Polymer app from the Dart IDE, I get an error that says cannot call flash() on null.
I ended up making it flash by just using an event bus and letting PolyComp listen to my event, but this is overkill.
What am I doing wrong? This happens in the latest Chrome, Firefox and Safari.
Edit:
I built the following polymer app to JS also and ran into the same issue.
https://github.com/sethladd/dart-polymer-dart-examples/blob/master/web/todo_element/todo.html
Works on DartVM, not in Chrome because its calling a method on a null element.
When you run this code from the main() method it is probably a timing issue.
You can try something like
import "package:polymer/polymer.dart";
main() {
initPolymer().run(() {
// code here works most of the time
Polymer.onReady.then((e) {
// some things must wait until onReady callback is called
});
});
}
see also how to implement a main function in polymer apps

Twitter streaming api 140dev error

I am using 140dev Twitter Database Server (PHP) and I am continually getting this error in get_tweet.php. the error I'm getting from the php-error.log file in the Windows/Temp/ directory
PHP Notice: Undefined property: stdClass::$created_at in C:\inetpub\wwwroot\140dev\db\get_tweets.php on line 58
line 58 in get_tweets.php is:
$dateStamp = $this->oDB->telldate($tweet_object->created_at);
I'm not sure why I'm getting this error. There are tons of other instances where $tweet_object->created_at is being used, but I don't get error messages in the php-errors.log file.
Any help would be greatly appreciated!
Okay so I found out that the code I've inherited was not handling all the other messages that occur in the streaming api.
to fix the logged Notice I set an if check before the json processing code:
if(isset($tweet_object->created_at)){
//Do stuff
}
This resolved the Notice messages. It's annoying that I didn't think of a Null check earlier.
*Note: I did try using the property_exists() method in the if statement, but that still displayed the Notice message. Just in case anybody was interested.

Resources