0

I'm making a Google Chrome extension that parses a Twitter feed's source code when the user inputs the handle. I'm aware that you cannot extract an external site's source code unless you give it permission in the manifest.json file. However, the URL in my case will vary based on the Twitter handle that the user inputs, so how can I edit the manifest file directly from my popup.js script?

For example, I want something like this:

{
    "permissions": [
        "http://www.twitter.com/" + handle + "/with_replies"
    ]
}

in my manifest.json file and

var handle = "CNN";
$(document).ready(function() {
    $.get("http://www.twitter.com/" + handle + "/with_replies", function(data) {
        $("#body").text(data);
    });
});

to return the content of the Twitter feed for CNN.

************************************************ UPDATE ************************************************

So to test to see if my code works, I changed my manifest.json file to include http://www.twitter.com/* as a permission, and I changed my jQuery code to:

$.get("https://twitter.com/", function(data) {
    $("h5").text(data);
    });
});

This is inside an event listener that listens for a button click, so this should change the text of the h5 element to the source of the webpage, but it doesn't. I've tried replacing https://www.twitter.com/* with https://www.twitter.com/ and it still doesn't work. But if I replace the jQuery code with something simple like $("h5").text("Hello world!");, it works fine. Is there something wrong with my jQuery code to extract the page's content?

This is what the permissions section in my manifest file looks like:

"permissions": [
 "activeTab",
 "storage",
 "https://twitter.com/*"
]
EliteKnight
  • 87
  • 1
  • 11
  • 2
    You can't, the manifest is processed by the browser.... even if you could change it, the changes probably would not take effect. – Mottie Jan 14 '17 at 19:30
  • 2
    I think you could just put "`http://www.twitter.com`" on permissions.. or maybe "`http://www.twitter.com/*`" – Felipe Nathan Campigoto Jan 14 '17 at 19:31
  • @FelipeNathanCampigoto Thanks for the reply. I've tried your suggestions, but now there seems to be an issue with the execution of the jQuery, which I've updated above. – EliteKnight Jan 14 '17 at 21:08
  • 1
    @FelipeNathanCampigoto Nevermind it works, it just took a little while to load :) – EliteKnight Jan 14 '17 at 21:51

1 Answers1

0

I doubt you could edit the file for security reasons. However, it you could have multiple content_scripts executing on different occasions. So if your condition is meet on that website, it will execute.

"content_scripts": [
  {
    "matches": ["https://www.google.com/*"],
    "js": ["jquery.js", "myGoogleScript.js"]
  },
  {
    "matches": ["http://www.example.com/*"],
    "js": ["jquery.js", "myExampleScript.js"]
  }
]

For more go to: Possible to have multiple content scripts for different functions?

Community
  • 1
  • 1
Zekrom_Vale
  • 344
  • 4
  • 10