Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

功能使用七:使用响应头重写功能,解决跨域问题 #143

Open
jingjingxyk opened this issue Jan 26, 2023 · 0 comments
Open

Comments

@jingjingxyk
Copy link
Contributor

jingjingxyk commented Jan 26, 2023

缘由:临时起意,想看deno在【微博站点或者微信公众号】中被搜索引擎收录情况,并且把结果显示在指定站点

关键点: 解决不同站点之间的跨域问题

例子总共分三步:
-- 步骤一: 添加自定义规则
-- 步骤二: 打开站点 https://justjavac.com/ 页面下的web控制台,并执行下面的脚本
-- 步骤三:观察控制台结果(发现,跨域已经被解决)

步骤一: 自定义规则例子:

关键点: 设置access-control-allow-origin,最宽泛的是设置为*,当然也可以设置为指定的站点地址

{
  "action": {
    "requestHeaders": [
      {
        "header": "referer",
        "operation": "set",
        "value": "https://www.baidu.com"
      },
      {
        "header": "origin",
        "operation": "set",
        "value": "https://www.baidu.com"
      }
    ],
    "responseHeaders": [
      {
        "header": "access-control-allow-origin", 
        "operation": "set",
        "value": "*"
      },
      {
        "header": "set-cookie",
        "operation": "remove"
      }
    ],
    "type": "modifyHeaders"
  },
  "condition": {
    "initiatorDomains": [
      "justjavac.com",
      "jingjingxyk.com"
    ],
    "requestDomains": [
      "www.baidu.com"
    ],
    "resourceTypes": [
      "main_frame",
      "sub_frame",
      "stylesheet",
      "script",
      "image",
      "font",
      "object",
      "xmlhttprequest",
      "ping",
      "csp_report",
      "media",
      "websocket",
      "webtransport",
      "webbundle",
      "other"
    ],
    "urlFilter": "https://www.baidu.com/s?ie=utf-8&wd=*"
  },
  "id": 20015,
  "priority": 10
}

步骤二: web控制台执行如下代码

{
   //let url='https://www.baidu.com/s?ie=utf-8&wd=deno%20site%3A%20weibo.com'
    let url='https://www.baidu.com/s?ie=utf-8&wd=deno%20site%3Amp.weixin.qq.com'
    fetch(url).then(res=>res.text()).then((res)=>{
          let content=(new DOMParser()).parseFromString(res,'text/html').body
          console.log(content)
    })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant