Search code examples
javascriptgoogle-chrome-extensionredditcontent-script

Chrome CORB just started blocking Snoowrap Reddit API calls. How do I get around this?


I've been working on a Chrome extension that calls the Reddit API using Snoowrap installed by Node. It's been working great until today. All my requests now return empty responses, and I get the following warning in the console:

Cross-Origin Read Blocking (CORB) blocked cross-origin response https://oauth.reddit.com/r/askreddit/hot?raw_json=1&count=9999&t= with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.

I've been testing with a simple request and that's failing. This is in a Content Script, using Browserify:

var snoowrap = require('snoowrap');
var CONFIG = require('./config.json');
var hiddenUpvoteElements;

var r = new snoowrap({
    userAgent: CONFIG.userAgent,
    clientId: CONFIG.clientId,
    clientSecret: CONFIG.clientSecret,
    refreshToken: CONFIG.refreshToken
});

r.getSubreddit("askreddit").getHot().then(console.log);

Relevant manifest.json stuff (tried a lot of different things to try and get it to work):

"manifest_version": 2,
"permissions": [
    "tabs",
    "https://www.reddit.com/*",
    "https://old.reddit.com/*",
    "activeTab",
    "https://oauth.reddit.com/*"
],
"background": {
    "scripts": ["background.js"]
},
"content_scripts": [
    {
        "matches": ["*://*.reddit.com/*"],
        "js": ["bundle.js"],
        "run_at": "document_end"
    }
],
"content_security_policy": "script-src 'self' https://oauth.reddit.com; object-src 'self'"

I find it really weird because it's been working fine until today. My computer restarted yesterday, and maybe it applied an update to the OS or Chrome or something. I tested using Python and Praw with the same info that I used to initialize the snoowrap instance, and it works with that.

Any advice on what I can do to get around this would be appreciated. Thanks in advance.


Solution

  • As directed to by wOxxOm, I solved the issue by moving the requests to a background script, and using messages to relay the results back to my content script.