Chrome extension .json file error when uploading

前端 未结 2 1653
没有蜡笔的小新
没有蜡笔的小新 2020-12-22 06:40

I have a manifest.json file like this:

{
  \"name\": \"YouTube Trending to Paid promotion!\",
  \"manifest_version\": 2,
  \"version\": \"1.0\",         


        
2条回答
  •  时光说笑
    2020-12-22 07:11

    The problem, as the error states, is that your matches value is invalid. The Match Patterns documentation explains that *, when used in the host portion, has the following requirements:

    * in the host can be followed only by a . or /
    If * is in the host, it must be the first character

    Thus, your match pattern of:

    "matches": ["*://*.youtube.*/*"],
    

    is invalid because the second * (youtube.*) is not permitted.

    Explicitly list the Top Level Domains (TLDs) you desire to match

    You need to explicitly determine the TLDs you desire to match, then include a list of them in your matches array. For example:

    "matches": [
        "*://*.youtube.com/*",
        "*://*.youtube.co.uk/*"
    ],
    

    However, for YouTube, they appear to redirect all traffic to youtube.com. Thus, you are probably just fine using:

    "matches": ["*://*.youtube.com/*"],
    

    This matching limitation is by design. There are a large number of TLDs, and more are likely to be created in the future. There is no guarantee that a particular site which you desire to match currently has a domain in every TLD, nor that they will obtain one in every new TLD which is created. Thus, the better solution is to not permit wildcards for the TLD when a portion of the host is specified.

    Alternately, use include_globs, but then have possible false matches

    You can use include_globs to obtain what you desire, but doing so has security risks due to possible false matches. You would need something like:

    "content_scripts": [
      {
        "matches": ["*://*/*"],
        "js": ["popup.js"],
         "include_globs": [
           "http://*.youtube.*/*",
           "https://*.youtube.*/*"
         ]
      }
    ]
    

    This is still imperfect, as it will match URLs which contain .youtube.*/* anywhere in their URL (e.g. http://foo.example.com/clone/www.youtube.com/myVideo). Unfortunately, because include_globs is a glob, not a full regular expression, you can not specify that you want to match all characters but /, which you could do in a regular expression (e.g. [^/]). Overall, you are better off explicitly determining the TLDs you desire to match, then include a list of them in your matches array.

    Note: In the above example, your matches pattern could be either "*://*/*", or "". The difference is that "" also matches "file:" and "ftp:" URLs, which are then excluded by the include_globs.

提交回复
热议问题