Affichage des articles dont le libellé est google chrome. Afficher tous les articles
Affichage des articles dont le libellé est google chrome. Afficher tous les articles
5/05/2012

How to fix the "Could not decode a text frame as UTF-8." bug

Sometimes Google Chrome throw a Could not decode a text frame as UTF-8 error. It happens when the server send invalid unicode characters (see Unicode surrogates) to the browser (via websockets or any other transport) and . I've found two work-around for this issue.

The first one is from my point of view, the best approach (the original code came from SockJS codebase). It removes all the invalid unicode characters from the string so you can send it from the server-side without further decoding.

/*
 * Fix the "Could not decode a text frame as UTF-8." bug #socket.io #nodejs #websocket
 *
 * Usage:
 *   cleanedString = filterUnicode(maybeHarmfulString);
 *
 * Original work-around from SockJS: https://github.com/sockjs/sockjs-node/commit/e0e7113f0f8bd8e5fea25e1eb2a8b1fe1413da2c
 * Other work-around: https://gist.github.com/2024272
 * 
 */

var escapable = /[\x00-\x1f\ud800-\udfff\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufff0-\uffff]/g;

function filterUnicode(quoted){

  escapable.lastIndex = 0;
  if( !escapable.test(quoted)) return quoted;

  return quoted.replace( escapable, function(a){
    return '';
  });
}

The second one takes another approach which seems valid (I only tested the former) but requires an extra decoding step on the other side:

/**
 * encode to handle invalid UTF
 * 
 * If Chrome tells you "Could not decode a text frame as UTF-8" when you try sending
 * data from nodejs, try using these functions to encode/decode your JSON objects.
 * 
 * see discussion here: http://code.google.com/p/v8/issues/detail?id=761#c8
 * see also, for browsers that don't have native JSON: https://github.com/douglascrockford/JSON-js
 * 
 * Any time you need to send data between client and server (or vice versa), encode before sending,
 * and decode upon receiving. This is useful, for example, if you are using socket.io for real-time
 * client/server communication of data fetched from a third-party service like Twitter, which might
 * contain Emoji, or other UTF characters outside the BMP.
 */
function strencode( data ) {
  return unescape( encodeURIComponent( JSON.stringify( data ) ) );
}

function strdecode( data ) {
  return JSON.parse( decodeURIComponent( escape ( data ) ) );
}

Hope this help !

[Update] Dougal Campbell made some important notes: “the second method preserves the original data, while the first strips out information, altering the original data”. Thus, the first method can lead to potential security leaks (see his comment).

2/25/2011

Growl Mac pour l'API de notification Google Chrome (poc)

Extension Google Chrome Growl pour les notifications web
Peut-être avez-vous vu passé ce tweet:
Je comprends tout à fait que le staff en charge de Chrome ne souhaite pas développer des extensions spécifiquement pour Mac (ou Windows ou Linux). Mais même si Growl n'est pas intégré en natif sous Mac, il est dommage de ne pas en profiter lorsqu'il est présent sur la machine. L'autre raison de cette non implémentation est que Growl ne gère pas les notifications de type HTML alors que ce type de notification est possible via l'API Web Notification.

Enfin si aucune extension Google Chrome pour Growl Mac n'existe c'est parce qu'il est impossible d'appeler un exécutable (dans notre cas Growlnotify) depuis une extension (pour des raisons de sécurité bien évidement).

Il faudrait donc pouvoir exécuter un exécutable depuis une extension Google Chrome. Une solution possible est de communiquer via websocket avec un serveur NodeJS local qui se chargera d'exécuter Growlnotify:


L'extension ChromeGrowl surcharge la méthode createNotification ainsi que createHTMLNotification de l'API de notification. Voici l'extension en action:


Le support de createHTMLNotification est pour le moment quasiment inexistant car dans la majorité des cas une requête cross-domain est requise. La solution serait d'envoyer l'url au serveur node qui téléchargerait le contenu puis après analyse afficherait le plus d'informations possible via Growl.

Le code est disponible sur mon GitHub Chrome-Growl-Notification. Il s'agit d'un proof of concept réalisé en quelques heures n'hésitez pas à le forker pour l'améliorer ou corriger de possibles bugs.

EDIT: Je viens de découvrir qu'il faut payer une taxe de 5$ pour pouvoir publier des plugins sur le Google Chrome Extensions Directory. Je ne compte pas verser le moindre $ pour un petit POC, néanmoins si l'envie vous en dit vous pouvez toujours faire un don :).

Sources:
»
 
 
Made with on a hot august night from an airplane the 19th of March 2017.