Skip to content

Circumvent TrustedHTML errors #1873

@psultan

Description

@psultan

Sequence of actions:

  1. Install Userscript
// ==UserScript==
// @name        Hello
// @namespace   Violentmonkey Scripts
// @match       https://calendar.google.com/calendar/*
// @require     http://code.jquery.com/jquery-latest.min.js
// @icon        https://www.google.com/s2/favicons?domain=google.com
// @grant       none
// @version     1.0
// ==/UserScript==
(function() {
    'use strict';
    console.log("Hello")
})();
  1. Goto https://calendar.google.com/calendar/

Problem:

In Chrome Beta some sites are throwing a 'This document requires 'TrustedHTML' assignment.' error when the script sources a require file. This is only happening in Chrome Beta now, but will likely be an issue in standard Chrome in the future.

This tampermonkey ticket seems related: Tampermonkey/tampermonkey#1334. Using the linked 'Trusted-Types Helper' with violentmonkey fixes the issue for toplevel matches, but does not fix it for sub-frames (goto gmail and open calander sidepanel). If I use the latest tampermonkey the require works on both toplevel and sub-frames (without the helper).

Devtools console contents:

This document requires 'TrustedHTML' assignment.
    (anonymous)	@	Hello.user.js:2
    ib	@	Hello.user.js:2
    fb.setDocument	@	Hello.user.js:2
    (anonymous)	@	Hello.user.js:2
    (anonymous)	@	Hello.user.js:2
    (anonymous)	@	Hello.user.js:2
    (anonymous)	@	Hello.user.js:2
    VMl5m11cb4xv	@	Hello.user.js:20
    Ut	@	injected-web.js:1
    (anonymous)	@	Hello.user.js:1
    Et	@	injected.js:1
    Dt	@	injected.js:1
    await in Dt (async)		
    St	@	injected.js:1
    $t	@	injected.js:1
    await in $t (async)		
    (anonymous)	@	injected.js:1
    await in (anonymous) (async)		
    (anonymous)	@	injected.js:1
    (anonymous)	@	injected.js:1

Environment:

  • OS: Windows
  • Browser: Chrome Version 117.0.5938.11 (Official Build) beta (64-bit)
  • Violentmonkey Version: 2.15.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions