Skip to content

Commit

Permalink
#203 websockets
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizzick committed May 5, 2016
1 parent 9471e0c commit c80af42
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Extension/lib/content-script/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
}
}

// Override window.WebSocket
// Override window.WebSocket running the function from websocket.js
// https://github.com/AdguardTeam/AdguardBrowserExtension/issues/203
scriptsToApply.unshift('(' + overrideWebSocket.toString() + ')();');

Expand Down
14 changes: 13 additions & 1 deletion Extension/lib/content-script/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
* along with Adguard Browser Extension. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* The function overrides window.WebSocket with our wrapper,
* that will check url with filters through messaging with content script.
*
* This function will be inlined as page script.
* https://github.com/AdguardTeam/AdguardBrowserExtension/issues/203
*/
var overrideWebSocket = function () {

'use strict';
Expand Down Expand Up @@ -198,6 +205,7 @@ var overrideWebSocket = function () {

};

// Safari doesn't have EventTarget
var EventTarget = window.EventTarget || Element;
WebSocket.prototype = Object.create(EventTarget.prototype, {
CONNECTING: {value: 0},
Expand Down Expand Up @@ -261,7 +269,11 @@ var overrideWebSocket = function () {
window.WebSocket = WebSocket;
};


/**
* Listener for websocket wrapper messages.
*
* @param event
*/
function pageMessageListener(event) {
if (!(event.source == window &&
event.data.direction &&
Expand Down

0 comments on commit c80af42

Please sign in to comment.