question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught (in promise) Error: Unexpected close tag ; Chrome User-Agent?

See original GitHub issue

I am currently seeing inconsistent behavior across browsers using rss-parser.

I am testing with this RSS feed: http://www.marketwatch.com/rss/topstories

I do get the same error for all RSS feeds I have tried on the same domain.

Here is the relevant code, Vue-flavored:

const CORS_PROXY = 'https://cors-anywhere.herokuapp.com/'

export default {
...
  mounted() {
    require('../../node_modules/rss-parser/dist/rss-parser.js')
    this.getFeeds()
  },

  methods: {
    async getFeeds() {
      const parser = new RSSParser({
        headers: {
          'User-Agent': 'rss-parser',
          'Cache-Control': 'no-cache',
          'Pragma': 'no-cache'
        },
        defaultRSS: 2.0,
        xml2js: {
          strict: true
        }
      })
      const feedRequests = this.$page.frontmatter.feeds.map(feed => {
        return parser.parseURL(CORS_PROXY + feed)
      })
      this.feeds = await Promise.all(feedRequests)
    }
  }
}

In Firefox, this will make a request that returns a valid RSS XML response; in Chrome, this is returning HTML, which makes rss-parser return the following error:

Uncaught (in promise) Error: Unexpected close tag
Line: 9
Column: 7
Char: >
    at error (rss-parser.js?e48f:12624)
    at strictFail (rss-parser.js?e48f:12648)
    at closeTag (rss-parser.js?e48f:12834)
    at SAXParser.write (rss-parser.js?e48f:13397)
    at Parser.parseString (rss-parser.js?e48f:11945)
    at Parser.eval [as parseString] (rss-parser.js?e48f:11620)
    at eval (rss-parser.js?e48f:8448)
    at new Promise (<anonymous>)
    at Parser.parseString (rss-parser.js?e48f:8447)
    at exports.IncomingMessage.eval (rss-parser.js?e48f:8520)

I can change all of the header attributes using the headers option, but User-Agent is the only one that will not change on Chrome (Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36). I suspect this has something to do with what I’m seeing.

Is there any way I can work around this? I will provide more information if necessary.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rbrencommented, Feb 26, 2019

Yes, this is an issue with the folks serving the RSS feeds. They see that the request is coming from a browser (by checking the User-Agent header) and decide to show an HTML page instead of RSS. Unfortunately you can’t change the User-Agent header due to browser security.

The only solution here is to create a proxy that lets you set the User-Agent header, e.g. by setting an X-Fake-User-Agent header.

1reaction
seeveecommented, Nov 5, 2019

Thanks for the reply @rbren, I figured as much.

At least this serves as a good example of why User Agent sniffing is nasty business.

Read more comments on GitHub >

github_iconTop Results From Across the Web

1295750 - console-entered error handling code is ... - Monorail
Specifically, the failure is that the underlying error objects are not passed to the handlers, as expected. What is the expected behavior? I ......
Read more >
json Uncaught SyntaxError: Unexpected token : - Stack Overflow
The issue really seems to be if the server responds with Type: text/javascript, then Chrome doesn't bark about Uncaught SyntaxError. If the ...
Read more >
Web Push Troubleshooting - OneSignal Documentation
This error only comes up when selecting the iPad or iPhone view in Chrome's dev tools which mocks the navigator.userAgent string to an...
Read more >
MediaDevices.getUserMedia() - Web APIs | MDN
It returns a Promise that resolves to a MediaStream object. If the user denies permission, or matching media is not available, then the...
Read more >
Puppeteer documentation - DevDocs
Puppeteer Documentation. Overview. Puppeteer is a Node library which provides a high-level API to control Chromium or Chrome over the DevTools Protocol. The ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found