From 70ae8d2168d6996b8becaaedbb86f56050c8845e Mon Sep 17 00:00:00 2001 From: Dustin Falgout Date: Tue, 10 May 2016 00:32:44 -0500 Subject: [PATCH] add bugsnag automated error reporting --- configure.ac | 4 +-- data/lightdm-webkit2-greeter.conf | 2 ++ src/lightdm-webkit2-greeter-ext.c | 47 +++++++++++++++++++++++--- src/lightdm-webkit2-greeter.c | 4 +-- themes/_vendor/js/bugsnag-2.5.0.min.js | 1 + 5 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 themes/_vendor/js/bugsnag-2.5.0.min.js diff --git a/configure.ac b/configure.ac index d90bd19..0a45dba 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. -AC_INIT(lightdm-webkit2-greeter, 2.1.4) +AC_INIT(lightdm-webkit2-greeter, 2.1.5) AC_SUBST(THEME_DIR) AC_CONFIG_HEADER(config.h) AC_PREREQ([2.59]) @@ -27,7 +27,7 @@ PKG_CHECK_MODULES([GREETER], [ ]) PKG_CHECK_MODULES([WEB_EXTENSION], [ - webkit2gtk-web-extension-4.0 >= 2.10.8 + webkit2gtk-web-extension-4.0 >= 2.10.7 ]) PKG_CHECK_MODULES([GREETER], [gtk+-3.0 >= 3.20], diff --git a/data/lightdm-webkit2-greeter.conf b/data/lightdm-webkit2-greeter.conf index 133f7ce..dafa30e 100644 --- a/data/lightdm-webkit2-greeter.conf +++ b/data/lightdm-webkit2-greeter.conf @@ -3,12 +3,14 @@ # webkit-theme = Webkit theme to use. (Default: antergos) # debug_mode = Greeter theme debug mode. (Default: false) # screensaver-timeout = Blank the screen after this many seconds of inactivity. (Default: 300) +# report-errors = Automatically report errors to the developers--anonymously. (Default: true) # [greeter] webkit-theme = antergos debug_mode = false screensaver-timeout = 300 +report-errors = true # # [branding] diff --git a/src/lightdm-webkit2-greeter-ext.c b/src/lightdm-webkit2-greeter-ext.c index 6f326c1..a3b6b18 100644 --- a/src/lightdm-webkit2-greeter-ext.c +++ b/src/lightdm-webkit2-greeter-ext.c @@ -1435,6 +1435,34 @@ static const JSClassDefinition greeter_util_definition = { }; +static void +inject_bugsnag_script(WebKitScriptWorld *world, WebKitFrame *frame) { + gchar *bugsnag, *string; + JSGlobalContextRef jsContext; + JSStringRef command; + + bugsnag = "4ea62a82" + "03b5b1af" + "7c33da0d" + "c2f6a60f"; + + string = g_strdup_printf( + "var s = document.createElement('script');" + "s.src = '../_vendor/js/bugsnag-2.5.0.min.js" + "s['data-apikey'] = %s;" + "$('head').append(s);", + bugsnag + ); + + jsContext = webkit_frame_get_javascript_context_for_script_world(frame, world); + command = JSStringCreateWithUTF8CString(string); + + JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL); + g_free(bugsnag); + g_free(string); +} + + static void window_object_cleared_callback(WebKitScriptWorld *world, WebKitWebPage *web_page, @@ -1447,6 +1475,8 @@ window_object_cleared_callback(WebKitScriptWorld *world, WebKitDOMDocument *dom_document; WebKitDOMDOMWindow *dom_window; gchar *message = "LockHint"; + gchar *theme; + gboolean report_errors; page_id = webkit_web_page_get_id(web_page); @@ -1498,19 +1528,28 @@ window_object_cleared_callback(WebKitScriptWorld *world, kJSPropertyAttributeNone, NULL); - - /* If the greeter was started as a lock-screen, send message to our UI process. */ if (lightdm_greeter_get_lock_hint(greeter)) { dom_document = webkit_web_page_get_dom_document(web_page); dom_window = webkit_dom_document_get_default_view(dom_document); if (dom_window) { - webkit_dom_dom_window_webkit_message_handlers_post_message(dom_window, - "GreeterBridge", message); + webkit_dom_dom_window_webkit_message_handlers_post_message( + dom_window, "GreeterBridge", message + ); } } + /* If the default theme is active & error reporting is enabled, inject bugsnag script */ + theme = g_key_file_get_string(keyfile, "greeter", "theme", NULL); + report_errors = g_key_file_get_boolean(keyfile, "greeter", "report-errors", NULL); + + if (strcmp("antergos", theme) == 0 && report_errors) { + inject_bugsnag_script(world, frame); + } + + g_free(theme); + } diff --git a/src/lightdm-webkit2-greeter.c b/src/lightdm-webkit2-greeter.c index 5e66107..50e057b 100644 --- a/src/lightdm-webkit2-greeter.c +++ b/src/lightdm-webkit2-greeter.c @@ -245,8 +245,8 @@ message_received_cb(WebKitUserContentManager *manager, static void quit_cb(void) { - gtk_widget_destroy(WEBKIT_WEB_VIEW(web_view)); - gtk_widget_destroy(GTK_WINDOW(window)); + gtk_widget_destroy(GTK_WIDGET(web_view)); + gtk_widget_destroy(GTK_WIDGET(window)); gtk_main_quit(); } diff --git a/themes/_vendor/js/bugsnag-2.5.0.min.js b/themes/_vendor/js/bugsnag-2.5.0.min.js new file mode 100644 index 0000000..2c87875 --- /dev/null +++ b/themes/_vendor/js/bugsnag-2.5.0.min.js @@ -0,0 +1 @@ +!function(a,b){function c(a,b){try{if("function"!=typeof a)return a;if(!a.bugsnag){var c=e();a.bugsnag=function(d){if(b&&b.eventHandler&&(u=d),v=c,!y){var e=a.apply(this,arguments);return v=null,e}try{return a.apply(this,arguments)}catch(f){throw l("autoNotify",!0)&&(x.notifyException(f,null,null,"error"),s()),f}finally{v=null}},a.bugsnag.bugsnag=a.bugsnag}return a.bugsnag}catch(d){return a}}function d(){B=!1}function e(){var a=document.currentScript||v;if(!a&&B){var b=document.scripts||document.getElementsByTagName("script");a=b[b.length-1]}return a}function f(a){var b=e();b&&(a.script={src:b.src,content:l("inlineScript",!0)?b.innerHTML:""})}function g(b){var c=l("disableLog"),d=a.console;void 0===d||void 0===d.log||c||d.log("[Bugsnag] "+b)}function h(b,c,d){if(d>=5)return encodeURIComponent(c)+"=[RECURSIVE]";d=d+1||1;try{if(a.Node&&b instanceof a.Node)return encodeURIComponent(c)+"="+encodeURIComponent(r(b));var e=[];for(var f in b)if(b.hasOwnProperty(f)&&null!=f&&null!=b[f]){var g=c?c+"["+f+"]":f,i=b[f];e.push("object"==typeof i?h(i,g,d):encodeURIComponent(g)+"="+encodeURIComponent(i))}return e.join("&")}catch(j){return encodeURIComponent(c)+"="+encodeURIComponent(""+j)}}function i(a,b){if(null==b)return a;a=a||{};for(var c in b)if(b.hasOwnProperty(c))try{a[c]=b[c].constructor===Object?i(a[c],b[c]):b[c]}catch(d){a[c]=b[c]}return a}function j(a,b){a+="?"+h(b)+"&ct=img&cb="+(new Date).getTime();var c=new Image;c.src=a}function k(a){var b={},c=/^data\-([\w\-]+)$/;if(a)for(var d=a.attributes,e=0;e\n";var f=[];try{for(var h=arguments.callee.caller.caller;h&&f.length"}return a.nodeName}}function s(){z+=1,a.setTimeout(function(){z-=1})}function t(a,b,c){var d=a[b],e=c(d);a[b]=e}var u,v,w,x={},y=!0,z=0,A=10;x.noConflict=function(){return a.Bugsnag=b,x},x.refresh=function(){A=10},x.notifyException=function(a,b,c,d){b&&"string"!=typeof b&&(c=b,b=void 0),c||(c={}),f(c),n({name:b||a.name,message:a.message||a.description,stacktrace:p(a)||o(),file:a.fileName||a.sourceURL,lineNumber:a.lineNumber||a.line,columnNumber:a.columnNumber?a.columnNumber+1:void 0,severity:d||"warning"},c)},x.notify=function(b,c,d,e){n({name:b,message:c,stacktrace:o(),file:a.location.toString(),lineNumber:1,severity:e||"warning"},d)};var B="complete"!==document.readyState;document.addEventListener?(document.addEventListener("DOMContentLoaded",d,!0),a.addEventListener("load",d,!0)):a.attachEvent("onload",d);var C,D=/^[0-9a-f]{32}$/i,E=/function\s*([\w\-$]+)?\s*\(/i,F="https://notify.bugsnag.com/",G=F+"js",H="2.4.8",I=document.getElementsByTagName("script"),J=I[I.length-1];if(a.atob){if(a.ErrorEvent)try{0===new a.ErrorEvent("test").colno&&(y=!1)}catch(K){}}else y=!1;if(l("autoNotify",!0)){t(a,"onerror",function(b){return function(c,d,e,g,h){var i=l("autoNotify",!0),j={};!g&&a.event&&(g=a.event.errorCharacter),f(j),v=null,i&&!z&&n({name:h&&h.name||"window.onerror",message:c,file:d,lineNumber:e,columnNumber:g,stacktrace:h&&p(h)||o(),severity:"error"},j),b&&b(c,d,e,g,h)}});var L=function(a){return function(b,d){if("function"==typeof b){b=c(b);var e=Array.prototype.slice.call(arguments,2);return a(function(){b.apply(this,e)},d)}return a(b,d)}};t(a,"setTimeout",L),t(a,"setInterval",L),a.requestAnimationFrame&&t(a,"requestAnimationFrame",function(a){return function(b){return a(c(b))}}),a.setImmediate&&t(a,"setImmediate",function(a){return function(){var b=Array.prototype.slice.call(arguments);return b[0]=c(b[0]),a.apply(this,b)}}),"EventTarget Window Node ApplicationCache AudioTrackList ChannelMergerNode CryptoOperation EventSource FileReader HTMLUnknownElement IDBDatabase IDBRequest IDBTransaction KeyOperation MediaController MessagePort ModalWindow Notification SVGElementInstance Screen TextTrack TextTrackCue TextTrackList WebSocket WebSocketWorker Worker XMLHttpRequest XMLHttpRequestEventTarget XMLHttpRequestUpload".replace(/\w+/g,function(b){var d=a[b]&&a[b].prototype;d&&d.hasOwnProperty&&d.hasOwnProperty("addEventListener")&&(t(d,"addEventListener",function(a){return function(b,d,e,f){try{d&&d.handleEvent&&(d.handleEvent=c(d.handleEvent,{eventHandler:!0}))}catch(h){g(h)}return a.call(this,b,c(d,{eventHandler:!0}),e,f)}}),t(d,"removeEventListener",function(a){return function(b,d,e,f){return a.call(this,b,d,e,f),a.call(this,b,c(d),e,f)}}))})}a.Bugsnag=x,"function"==typeof define&&define.amd?define([],function(){return x}):"object"==typeof module&&"object"==typeof module.exports&&(module.exports=x)}(window,window.Bugsnag);