TamperMonkey経由で任意のdomainのデータをfetchできるか試してみる
GM_xmlhttpRequestでは@connectでデータ取得先のdomainを指定する
これを@connect *にしたら、任意のdomainからデータを取得できるようになるだろうか?
試してみる
code:tampermonkey.js
// ==UserScript==
// @name url-info-proxy
// @namespace https://scrapbox.io
// @version 0.1
// @description fetch the title and OGP data from URL
// @author takker
// @match https://scrapbox.io/*
// @connect *
// @grant GM_xmlhttpRequest
// @license MIT
// @copyright Copyright (c) 2021 takker
// ==/UserScript==
"use strict"
unsafeWindow.fetchURLInfo = (url) => new Promise(resolve =>
GM_xmlhttpRequest({
method: "GET",
url,
onload: response => {
const html = response.responseText;
const dom = new DOMParser().parseFromString(html, 'text/html');
resolve(dom.title);
},
withCredentials: true,
})
);
面白い結果になったぞ!takker.icon
TamperMonkey側で、常にリソースアクセスを確かめるようになった!
https://gyazo.com/038c78fd2443dcdf0772959885319cc3
ちゃんとこういう安全装置がついているのか
user側で許可設定を行える
任意のdomainで確認なしに使うこともできるし
新しいdomainに対しては常に確認するようにもできる
2021-09-07 08:47:39 ていうか/ci7lus/たのしいScrapboxUserScript#5f63864eae0f140000027ce1に書いてあったじゃん……
気づかなかった
#2021-09-07 08:48:12
#2021-02-25 22:12:04