Log JavaScript errors in the Client Browser to the Server.
The goal is to allow the collection of JavaScript errors in the Client's Browser so that bugs can be fixed pro-actively and without need for specific interventions from the end user.
Requirements ¶
- Works with Yii 1.1.17 (probably with lower versions too).
- Uses http://jsnlog.com/ (included with the extension).
Usage ¶
- Add a Logger Controller.
You can use the included controller by creating "LoggerController.php" in the controllers directory like this:
<?php
Yii::import('ext.YJSNLog.LoggerController',true);
That controller adds the messages to the YiiLog.
Then you have to initiate the logging by calling the widget. Here is a sample utility function:
/**
* Adds javascript debug to the HTML output.
*/
public static function setupJavaScriptDebug($reportUrl='logger/jsn') {
Yii::import('ext.YJSNLog.*');
Yii::app()->getController()
->widget('YJSNLog',array(
'handleOnError'=>true,
'ajaxAppenderOptions'=>array(
'url'=>Yii::app()->createUrl($reportUrl),
'disallow'=>implode(
'|',
array(
// Parts of expressions that should not be logged.
'"url":"https://maps.gstatic.com/maps-api-v3'
,'at Zba'
,'document.querySelector..title...textContent'
,"'removeChild'"
,'//tags.bkrtx.com/js/bk-coretag.js'
,'"msg":"Exception!","errorMsg":"Script error.","url":"","line number":0'
)
)
),
));
}
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.