Skip to content

Cannot inject functions into unsafeWindow on Twitter #2223

Description

@Zezombye

Expected Behavior

Adding functions to unsafeWindow works, eg on youtube:

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      2024-11-02
// @description  try to take over the world!
// @author       You
// @match        https://www.youtube.com/watch?v=Bv1LVYtdGGo
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        unsafeWindow
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    unsafeWindow.test1 = "test"
    unsafeWindow.test2 = () => "test"
})();

image

Actual Behavior

Running the following userscript gives:

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      2024-11-02
// @description  try to take over the world!
// @author       You
// @match        https://x.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=x.com
// @grant        unsafeWindow
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    unsafeWindow.test1 = "test"
    unsafeWindow.test2 = () => "test"
})();

image

Functions cannot be accessed in any way. (Probably a CSP issue?)

Tested while disabling all other scripts.

Specifications

  • Firefox: 132.0
  • TM: 5.3.1
  • OS: Windows 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions