はてなキーワード: application/xmlとは
数日前に puppeteer で自動で PDF にする試みを書いたブログがホッテントリに入ってるのを見た
bg.js
const username = "" const api_key = "" chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { if(message.bookmark){ bookmark(message.bookmark) } }) async function bookmark(url){ fetch("http://b.hatena.ne.jp/atom/post", { method: "POST", referrer: "no-referrer", headers: { Accept: "application/x.atom+xml, application/xml, text/xml, */*", "X-WSSE": await createCredential(), }, body: ` <entry xmlns="http://purl.org/atom/ns#"> <link rel="related" type="text/html" href="${url}" /> </entry> `.replace(/\t/g, ""), }).then(e => {console.log(e)}) } async function createCredential(){ const non = Math.random().toString(36).substr(2) const now = new Date().toISOString() const buf = new TextEncoder().encode(non + now + api_key) const u8a = new Uint8Array(await crypto.subtle.digest("SHA-1", buf)) const str = Array.from(u8a, e => String.fromCharCode(e)).join("") const b64 = btoa(str) return `UsernameToken Username="${username}", PasswordDigest="${b64}", Nonce="${btoa(non)}", Created="${now}"` }
username と api_key を埋めてバックグラウンドで動かす
page.js
chrome.runtime.sendMessage({ bookmark: location.href })
ページ内で動かすコード
どうしたんかいな、とネットワークトレースをとってみた。そしたら、トップ画面の要求に対してこんな応答が返っていた。
GET / HTTP/1.1 Host: www.yodobashi.com Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: ja,en-us;q=0.7,en;q=0.3 Accept-Encoding: gzip,deflate Accept-Charset: Shift_JIS,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive HTTP/1.1 200 OK Date: Wed, 29 Oct 2008 02:02:31 GMT Server: Apache Pragma: no-cache Cache-Control: private Expires: -1 Set-Cookie: JSESSIONID=FAE13F42154EB566479E047B57CBF2EA; Path=/cs Set-Cookie: SS_X_JSESSIONID=AFA6E52B61BCC8A2C2704B1F60B98B6A; Path=/ Set-Cookie: SS_X_JSESSIONID=AFA6E52B61BCC8A2C2704B1F60B98B6A; Path=/ Set-Cookie: SS_X_JSESSIONID=AFA6E52B61BCC8A2C2704B1F60B98B6A; Path=/ Set-Cookie: SS_X_JSESSIONID=AFA6E52B61BCC8A2C2704B1F60B98B6A; Path=/ Set-Cookie: SS_X_JSESSIONID=AFA6E52B61BCC8A2C2704B1F60B98B6A; Path=/ Set-Cookie: SS_X_JSESSIONID=AFA6E52B61BCC8A2C2704B1F60B98B6A; Path=/ Set-Cookie: SS_X_JSESSIONID=AFA6E52B61BCC8A2C2704B1F60B98B6A; Path=/ Set-Cookie: SS_X_JSESSIONID=AFA6E52B61BCC8A2C2704B1F60B98B6A; Path=/ Set-Cookie: SS_X_JSESSIONID=AFA6E52B61BCC8A2C2704B1F60B98B6A; Path=/ Set-Cookie: BIGipServerPool_www_yodobashi_com_cms=1258399936.20480.0000; path=/ Content-Length: 83878 Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Content-Type: text/html;charset=Windows-31J
えーと。どこから突っ込んでいいのやら。