Skip to content

Instantly share code, notes, and snippets.

@lulzsun
Last active March 11, 2023 16:27
Show Gist options
  • Select an option

  • Save lulzsun/f8eff07e74b40126866d83a17d0fb256 to your computer and use it in GitHub Desktop.

Select an option

Save lulzsun/f8eff07e74b40126866d83a17d0fb256 to your computer and use it in GitHub Desktop.

Revisions

  1. lulzsun revised this gist Mar 11, 2023. 2 changed files with 13 additions and 5 deletions.
    7 changes: 6 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -33,4 +33,9 @@ The script will intercept http POST requests and modify the request body to remo

    [Alternative solutions](https://github.com/imdonix/canvas-antidetect) tend to patch (prototype polluting) browser events that send the `window.blur` and `window.focus` events.

    However, this script takes a different approach by patching `window.XMLHttpRequest` to intercept and modify the requests before being sent, which achieves the same result. I feel like this is a cleaner approach and doesn't mess with page functionality relating to blur and focus.
    However, this script takes a different approach by patching `window.XMLHttpRequest` to intercept and modify the requests before being sent, which achieves the same result. I feel like this is a cleaner approach and doesn't mess with page functionality relating to blur and focus.

    Optionally, you can choose to disable the userscript temporarily by opening up the developer tools and type the following:
    ```js
    window.cantvas = false;
    ```
    11 changes: 7 additions & 4 deletions canTvas.user.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    // @name canTvas
    // @namespace https://gist.github.com/lulzsun/f8eff07e74b40126866d83a17d0fb256
    // @downloadURL https://gist.github.com/lulzsun/f8eff07e74b40126866d83a17d0fb256/raw/canTvas.user.js
    // @version 0.1
    // @version 0.2
    // @description Prevents the logging of specific canvas lms quiz events.
    // @author lulzsun
    // @match http*://*.instructure.com/*
    @@ -13,7 +13,8 @@

    (function() {
    'use strict';


    window.cantvas = true;
    var oldXHROpen = window.XMLHttpRequest.prototype.open;
    var oldXHRSend = window.XMLHttpRequest.prototype.send;
    window.XMLHttpRequest.prototype.open = function (method, url) {
    @@ -29,17 +30,19 @@
    // testing for quiz events
    var regexMatches = new RegExp("*/api/v1/courses/*/quizzes/*/submissions/*/events".replace(/\*/g, "[^ ]*"));

    if (regexMatches.test(url)) {
    if (regexMatches.test(url) && window.cantvas === true) {
    if (body !== undefined) {
    var parsedBody = JSON.parse(body);
    var i = parsedBody["quiz_submission_events"].length;
    var prevents = 0;
    while (i--) {
    var element = parsedBody["quiz_submission_events"][i];
    if (element["event_type"] === "page_focused" || element["event_type"] === "page_blurred") {
    parsedBody["quiz_submission_events"].splice(i, 1);
    console.warn(`[canTvas] '${element["event_type"]}' event was prevented.`);
    prevents++;
    }
    }
    if (prevents > 0) console.warn(`[canTvas] '${prevents}' event(s) were prevented.`);
    args[0] = JSON.stringify(parsedBody["quiz_submission_events"]);
    console.log('on send body:', parsedBody["quiz_submission_events"]);
    if (parsedBody["quiz_submission_events"].length <= 0)
  2. lulzsun revised this gist Mar 6, 2023. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ This script prevents Canvas from recieving or logging certain user interactions
    1. First you need a userscript manager such as: **Tampermonkey**
    - [Chrome](https://chrome.google.com/webstore/detail/dhdgffkkebhmkfjojejmpbldmpobfkfo)
    - [Firefox](https://addons.mozilla.org/en-US/firefox/addon/tampermonkey/)
    2. Install the script [Here](https://gist.github.com/lulzsun/f8eff07e74b40126866d83a17d0fb256/raw/canTvas.js)!
    2. Install the script [Here](https://gist.github.com/lulzsun/f8eff07e74b40126866d83a17d0fb256/raw/canTvas.user.js)!

    ## Warning
    Make sure the script loads before attempting any tomfoolery. You can open up the developer console and check for a `console.warn` message that looks like this:
    2 changes: 1 addition & 1 deletion canTvas.js → canTvas.user.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // ==UserScript==
    // @name canTvas
    // @namespace https://gist.github.com/lulzsun/f8eff07e74b40126866d83a17d0fb256
    // @downloadURL https://gist.github.com/lulzsun/f8eff07e74b40126866d83a17d0fb256/raw/canTvas.js
    // @downloadURL https://gist.github.com/lulzsun/f8eff07e74b40126866d83a17d0fb256/raw/canTvas.user.js
    // @version 0.1
    // @description Prevents the logging of specific canvas lms quiz events.
    // @author lulzsun
  3. lulzsun revised this gist Mar 6, 2023. No changes.
  4. lulzsun revised this gist Mar 6, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion canTvas.js
    Original file line number Diff line number Diff line change
    @@ -37,7 +37,7 @@
    var element = parsedBody["quiz_submission_events"][i];
    if (element["event_type"] === "page_focused" || element["event_type"] === "page_blurred") {
    parsedBody["quiz_submission_events"].splice(i, 1);
    console.warn(`[canTvas] '${element["event_type"]}' event was prevented!`);
    console.warn(`[canTvas] '${element["event_type"]}' event was prevented.`);
    }
    }
    args[0] = JSON.stringify(parsedBody["quiz_submission_events"]);
  5. lulzsun revised this gist Mar 6, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion canTvas.js
    Original file line number Diff line number Diff line change
    @@ -37,7 +37,7 @@
    var element = parsedBody["quiz_submission_events"][i];
    if (element["event_type"] === "page_focused" || element["event_type"] === "page_blurred") {
    parsedBody["quiz_submission_events"].splice(i, 1);
    console.warn(`[canTvas] '${element["event_type"]}' event was prevented.`);
    console.warn(`[canTvas] '${element["event_type"]}' event was prevented!`);
    }
    }
    args[0] = JSON.stringify(parsedBody["quiz_submission_events"]);
  6. lulzsun renamed this gist Mar 6, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. lulzsun revised this gist Mar 6, 2023. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion canTvas.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // ==UserScript==
    // @name canTvas
    // @namespace https://gist.github.com/lulzsun/f8eff07e74b40126866d83a17d0fb256
    // @downloadURL https://gist.github.com/lulzsun/f8eff07e74b40126866d83a17d0fb256/raw/8cb5ef3199d0c7a466df657cc1c207265a11b3d4/canTvas.js
    // @downloadURL https://gist.github.com/lulzsun/f8eff07e74b40126866d83a17d0fb256/raw/canTvas.js
    // @version 0.1
    // @description Prevents the logging of specific canvas lms quiz events.
    // @author lulzsun
    2 changes: 1 addition & 1 deletion README.md → canTvas.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ This script prevents Canvas from recieving or logging certain user interactions
    1. First you need a userscript manager such as: **Tampermonkey**
    - [Chrome](https://chrome.google.com/webstore/detail/dhdgffkkebhmkfjojejmpbldmpobfkfo)
    - [Firefox](https://addons.mozilla.org/en-US/firefox/addon/tampermonkey/)
    2. Install the script [Here](https://gist.github.com/lulzsun/f8eff07e74b40126866d83a17d0fb256/raw/6efe3f9f788475f10fe075061d2ba2023a18a8a4/canTvas.js)!
    2. Install the script [Here](https://gist.github.com/lulzsun/f8eff07e74b40126866d83a17d0fb256/raw/canTvas.js)!

    ## Warning
    Make sure the script loads before attempting any tomfoolery. You can open up the developer console and check for a `console.warn` message that looks like this:
  8. lulzsun revised this gist Mar 6, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ This script prevents Canvas from recieving or logging certain user interactions
    1. First you need a userscript manager such as: **Tampermonkey**
    - [Chrome](https://chrome.google.com/webstore/detail/dhdgffkkebhmkfjojejmpbldmpobfkfo)
    - [Firefox](https://addons.mozilla.org/en-US/firefox/addon/tampermonkey/)
    2. Install the script [Here](https://gist.github.com/lulzsun/f8eff07e74b40126866d83a17d0fb256/raw/8cb5ef3199d0c7a466df657cc1c207265a11b3d4/canTvas.js)!
    2. Install the script [Here](https://gist.github.com/lulzsun/f8eff07e74b40126866d83a17d0fb256/raw/6efe3f9f788475f10fe075061d2ba2023a18a8a4/canTvas.js)!

    ## Warning
    Make sure the script loads before attempting any tomfoolery. You can open up the developer console and check for a `console.warn` message that looks like this:
  9. lulzsun revised this gist Mar 6, 2023. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # canTvas
    This script prevents Canvas from recieving certain user interactions (specifically `page_focused` and `page_blurred`).
    This script prevents Canvas from recieving or logging certain user interactions during quizzes (specifically `page_focused` and `page_blurred`).

    # Install
    1. First you need a userscript manager such as: **Tampermonkey**
    @@ -22,10 +22,12 @@ Do note that this script could break depending if Canvas instructure changes the
    var regexMatches = new RegExp("*/api/v1/courses/*/quizzes/*/submissions/*/events".replace(/\*/g, "[^ ]*"));
    ```

    Be cautious monitor network POST requests and see if any `page_focused` or `page_blurred` events are being sent. A request payload could look something like this:
    Be cautious and monitor network POST requests to see if any `page_focused` or `page_blurred` events are being sent during a quiz. A request payload could look something like this:

    ![Payload](https://raw.githubusercontent.com/imdonix/canvas-antidetect/master/doc/logger.png)

    If you do not see any payloads with these events then you are probably safe!

    ## How it works
    The script will intercept http POST requests and modify the request body to remove the specified events.

  10. lulzsun revised this gist Mar 6, 2023. 2 changed files with 36 additions and 2 deletions.
    35 changes: 34 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,34 @@
    # canTvas
    # canTvas
    This script prevents Canvas from recieving certain user interactions (specifically `page_focused` and `page_blurred`).

    # Install
    1. First you need a userscript manager such as: **Tampermonkey**
    - [Chrome](https://chrome.google.com/webstore/detail/dhdgffkkebhmkfjojejmpbldmpobfkfo)
    - [Firefox](https://addons.mozilla.org/en-US/firefox/addon/tampermonkey/)
    2. Install the script [Here](https://gist.github.com/lulzsun/f8eff07e74b40126866d83a17d0fb256/raw/8cb5ef3199d0c7a466df657cc1c207265a11b3d4/canTvas.js)!

    ## Warning
    Make sure the script loads before attempting any tomfoolery. You can open up the developer console and check for a `console.warn` message that looks like this:

    ```
    [canTvas] Userscript loaded successfully.
    ```

    If you don't see this, then it may be because the url doesn't fit `@match`. You will want to change that to fit your needs.

    Do note that this script could break depending if Canvas instructure changes the api url:
    ```js
    // testing for quiz events
    var regexMatches = new RegExp("*/api/v1/courses/*/quizzes/*/submissions/*/events".replace(/\*/g, "[^ ]*"));
    ```

    Be cautious monitor network POST requests and see if any `page_focused` or `page_blurred` events are being sent. A request payload could look something like this:

    ![Payload](https://raw.githubusercontent.com/imdonix/canvas-antidetect/master/doc/logger.png)

    ## How it works
    The script will intercept http POST requests and modify the request body to remove the specified events.

    [Alternative solutions](https://github.com/imdonix/canvas-antidetect) tend to patch (prototype polluting) browser events that send the `window.blur` and `window.focus` events.

    However, this script takes a different approach by patching `window.XMLHttpRequest` to intercept and modify the requests before being sent, which achieves the same result. I feel like this is a cleaner approach and doesn't mess with page functionality relating to blur and focus.
    3 changes: 2 additions & 1 deletion canTvas.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    // ==UserScript==
    // @name canTvas
    // @namespace https://github.com/lulzsun/canTvas
    // @namespace https://gist.github.com/lulzsun/f8eff07e74b40126866d83a17d0fb256
    // @downloadURL https://gist.github.com/lulzsun/f8eff07e74b40126866d83a17d0fb256/raw/8cb5ef3199d0c7a466df657cc1c207265a11b3d4/canTvas.js
    // @version 0.1
    // @description Prevents the logging of specific canvas lms quiz events.
    // @author lulzsun
  11. lulzsun created this gist Mar 6, 2023.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    # canTvas
    52 changes: 52 additions & 0 deletions canTvas.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    // ==UserScript==
    // @name canTvas
    // @namespace https://github.com/lulzsun/canTvas
    // @version 0.1
    // @description Prevents the logging of specific canvas lms quiz events.
    // @author lulzsun
    // @match http*://*.instructure.com/*
    // @match http*://*.canvas.*.edu/*
    // @icon https://www.google.com/s2/favicons?sz=64&domain=canvaslms.com
    // @grant none
    // ==/UserScript==

    (function() {
    'use strict';

    var oldXHROpen = window.XMLHttpRequest.prototype.open;
    var oldXHRSend = window.XMLHttpRequest.prototype.send;
    window.XMLHttpRequest.prototype.open = function (method, url) {
    this._url = url;
    var args = arguments;
    return oldXHROpen.apply(this, args);
    };

    window.XMLHttpRequest.prototype.send = function (body) {
    var url = this._url;
    var args = arguments;

    // testing for quiz events
    var regexMatches = new RegExp("*/api/v1/courses/*/quizzes/*/submissions/*/events".replace(/\*/g, "[^ ]*"));

    if (regexMatches.test(url)) {
    if (body !== undefined) {
    var parsedBody = JSON.parse(body);
    var i = parsedBody["quiz_submission_events"].length;
    while (i--) {
    var element = parsedBody["quiz_submission_events"][i];
    if (element["event_type"] === "page_focused" || element["event_type"] === "page_blurred") {
    parsedBody["quiz_submission_events"].splice(i, 1);
    console.warn(`[canTvas] '${element["event_type"]}' event was prevented.`);
    }
    }
    args[0] = JSON.stringify(parsedBody["quiz_submission_events"]);
    console.log('on send body:', parsedBody["quiz_submission_events"]);
    if (parsedBody["quiz_submission_events"].length <= 0)
    return;
    }
    }
    return oldXHRSend.apply(this, args);
    };

    console.warn(`[canTvas] Userscript loaded successfully.`);
    })();