Search code examples
google-apps-scriptimporturlfetchunexpected-tokenjssoup

JSSoup - SyntaxError: Unexpected token '<' Apps Script


In my Apps Script add-on, I need to use an external library JSSoup for managing some HTML text. I followed this answer to figure out how to add/import an external library in Apps Script. Then I added eval(UrlFetchApp.fetch('https://github.com/chishui/JSSoup/blob/master/lib/jssoup.js').getContentText(); in my script but it is throwing this error:

SyntaxError: Unexpected token '<'

No more logging available for this error. How can I resolve this error?


Solution

  • Upon checking the fetched content, it shows the all the page content rather than just the code. It is because you are getting all the content of that page, not just the code. Use the raw version instead by clicking the Raw icon and should redirect you to the correct link.

    raw

    Your command now should look like this:

    eval(UrlFetchApp.fetch('https://raw.githubusercontent.com/chishui/JSSoup/master/lib/jssoup.js').getContentText());

    Page vs Raw:

    difference

    Note:

    • Although after getting the proper content, you will encounter another issue. For that, you might need to post another question here for others to answer that issue.