Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This document requires 'TrustedScriptURL' assignment in Google Sheets

I have a Google Spreadsheet where I have the following information on specific cells in the sheet:

  • Cell B1: Has the URL http://www.google.com.co/search?q=NASA+watching+now%3A+site%3Awww.youtube.com
  • Cell B2: has the following formula: =IMPORTXML(B1,"//title")

Here is the link of the Google spreadsheet - if you want to test from your side.

And here is the Google Spreadsheet I'm working on - which, I want to get the specific data:

  1. Title: Text (in the h3 HTML tag of the result item).
  2. Url: Link (in the <a> HTML tag of the result item)
  3. Description: Text next to the thumbnail of the result item.

See screenshot with the data to get using IMPORTXML:

Screenshot of result item poiting the data to get with IMPORTXML

The previous code returns the title of the given URL - in this case, the URL stored in the B1 cell.

It was working without problems (since 12/02/2022 - dd/MM/yyyy) until today (13/02/2022 - dd/mm/yyyy).

I checked the Chrome console "F12 Developer tools" and I get this error:

This document requires 'TrustedScript' assignment.

injectIntoContentWindow @ VM364:27

By clicking the @ VM364:27 line, the following code is shown:

  function injectIntoContentWindow(contentWindow)
  {
    if (contentWindow && !injectedFramesHas(contentWindow))
    {
      injectedFramesAdd(contentWindow);
      try
      {
        contentWindow[eventName] = checkRequest;
        contentWindow.eval( /* ERROR with and (X) is shown here. */
          "(" + injectedToString() + ")('" + eventName + "', true);"
        );
        delete contentWindow[eventName];
      }
      catch (e) {}
    }
  }

Searching on the internet, I barely could get the causes of this error:

  • Google Chrome update - making security stricter.
  • Chrome extensions - try to disable such extensions and try again.
  • CPS (Content-Security-Policy) - must be honest = I don't understand this point; it's from the website to scrape the data OR from Google Sheets the CPS is the root cause?
  • The solutions given to this problem are in Python - with the use of DOMPurify - as is described in this answer, but, I don't know and neither have found any clues about this problem and its solution in Google Spreadsheets.

I've tried:

  • Recover previous working Google Spreadsheet version - the result is that the formula re-evaluates and no result is returned; looking in Console, the This document requires 'TrustedScriptURL' assignment message shows.
  • Disable Google Chrome installed extensions - I only have AdBlock (this code was working without issues), anyway, I turned off, reload the spreadsheet and the error mentioned above raises in Console.
  • Using another page - I tried with Wikipedia and Wiki.fandom and it works - i.e. data is returned. Probably in this case, Google injected in their searcher an script for avoid injection? - I'm really not sure, only speculating/rambling here.

Another possible cause I consider is maybe my IP was blacklisted or blocked, but, I'm not sure.

My browser information:

  • Chrome version: 98.0.4758.82 (Build oficial) (64 bits) (cohort: Stable)
  • Windows 10 Version 21H2 (Build 19044.1466)

Is there any way to solve this error in Google Sheets?

PS: I'm interested in know the workaround using google sheets and/or custom scripts - via script editor/Apps Script. The use of IMPORTXML function is not mandatory - I find curious that it was working and then today, not anymore.

like image 972
Marco Aurelio Fernandez Reyes Avatar asked May 07 '26 16:05

Marco Aurelio Fernandez Reyes


1 Answers

I will just leave this here:

=INDEX(UNIQUE(REGEXREPLACE(QUERY(IMPORTXML(A1, "//a/@href"), 
 "where Col1 contains 'youtube.com/'"), "\/url\?q=|&sa=.*", )))

enter image description here

=IMPORTXML(A1, "//title")

enter image description here

=IMPORTXML(A1, "//h3")

enter image description here

like image 189
player0 Avatar answered May 10 '26 18:05

player0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!