外部URLからリソースを使うには? | chrome extension
7月 28th, 2012
外部からリンクしてもエラーになるので・・・ようやくわかりました。 This webpage is not available The webpage at chrome-extension://invalid/ might be temporarily down or it may have moved permanently to a new web address. Error 2 (net::ERR_FAILED): Unknown error. Canaryだとちゃんとエラーが出るそうです・・・ Denying load of chrome-extension://…html. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension. GET […]
chrome extension で twitter oauth.
7月 27th, 2012
いろいろ修正しました。 重要追記:現時点では、リンクから chrome-extension:// を開けない仕様になっていることを確認しました。 手動で貼付ける場合は大丈夫ですが、外部URL内のリンクからは開けません. * これも間違いでした。。。登録するとリンクも利用出来ます。次のエントリーに書きます。。。 1つ目の方法は、javascriptに, consumer key , consumer secretを埋め込む方法。 こちらの方法は、丸見えなので、悪意のある人(開発者)が使うと twitterから制限されてしまいます。 2つ目は、サーバー側で取得した物をextensionに渡す。 http://www.eisbahn.jp/yoichiro/2011/10/chrome-extension-oauth.html 最初は、accesstokenをサーバー側で取得して渡すことを考えてしまったのですが、取得前のtokenを渡して javascript側でaccess_tokenを取りにいくので、問題ありませんでした。(1と同じ) 3つ目はすべてサーバー側。サーバーにログインさせる手間が発生するが、キー関連はサーバー側にあるので、取られることはない。 すべてを包括するアカウントが必要という・・・ chromeだからgoogle idでログインさせておけば良いかな。全部サーバー側でやらないといけないので微妙。 webRequest apiはxmlhttprequestはバグ?で取得出来ないみたいだけど。 http://code.google.com/chrome/extensions/tut_oauth.html * この辺も同じくリンクは開けない仕様に変わっている。 * manifest で追加設定が必要でした。 javascript内のconsumer key/secretが読まれてしまうが、これは定期的に更新したりすることで不正利用を回避。 なんとなく見えてきました。
badgeを表示 | chrome extension
7月 25th, 2012
desktop notificationも良いけど。バッヂでかなりアピールできるので http://code.google.com/chrome/extensions/browserAction.html Badge Browser actions can optionally display a badge — a bit of text that is layered over the icon. Badges make it easy to update the browser action to display a small amount of information about the state of the extension. Because the badge has limited space, it should have 4 characters […]
chrome.tags.getでエラーが出るので、onRemovedで先にチェックする
7月 24th, 2012
http://code.google.com/chrome/extensions/tabs.html chrome.tabs.get(tab.id ,function(tab){ if( typeof(tab)===’undefined’){ // not found }else{ } }); Error during tabs.get: No tab with id: 2187. sendRequest:20 chromeHidden.handleResponse undefinedの時は、タブが無いということで問題なく処理出来るのですが、(例外にもなりません。) consoleにメッセージがでるので、先に使えないIDをチェックします。 grBk.tabsに適当なタブのオブジェクトが入っていてtab.idでタブのIDを保持しています。 chrome.tabs.onRemoved.addListener(function( tabId, removeInfo) { // check active tab for( i in grBk.tabs ){ […]
エラーじゃないけど、function, lineNumberを取得する : javascript
7月 24th, 2012
開発中にエラーじゃないけど、エラー時のように関数、行番号を取得する。 console.log( (new Error()).stack ); Error at Object.init (chrome-extension://—/js/webdb.js:17:32) at chrome-extension://—/js/background.js:41:6 な感じになります。
chrome extensionを早く更新したいので、起動オプションを。for mac
4月 25th, 2012
本番にアップしてもすぐに更新できないので、chromeにオプションを付けて起動して一回更新してみる オプションの付け方は、こんな感じで、1は1分なので、1分前の更新を反映と言う感じでしょうか? open /Applications/Google\ Chrome.app –args –extensions-update-frequency=1 ( windows : chrome.exe –extensions-update-frequency=1 更新されたら、オプション無しで、再起動します。
chrome webstore テストアカウントに公開した後、一般公開する方法 | chrome extension
4月 17th, 2012
https://developers.google.com/chrome/web-store/docs/publish#testaccounts Note: To publish to the world after publishing to test accounts, you first need to unpublish the app. 一度非公開にする。
Refused to evaluate script because of Content-Security-Policy. | chrome extension
4月 15th, 2012
setTimeout で Refused to evaluate script because of Content-Security-Policy. のエラーメッセージ。 setTimeoutをどうやって表現するかと と思っていたら、ただ書き間違えていただけでした・・・ evalは使えませんが、普通に書く分には問題ないようです。
javascript closure compiler
4月 15th, 2012
複数ファイルを複数ファイルに出来ないのかな・・・?と思い。 compilerをダウンロード https://developers.google.com/closure/compiler/ $ cd compiler-latest/ COPYING README compiler.jar 複数ファイルを一つにするには、READMEに書いてある通り java -jar compiler.jar –js=in1.js –js=in2.js … –js_output_file=out.js .js:55: WARNING – Suspicious code. This code lacks side-effects. Is there a bug? reutrn; 普通に使うとエラー検出も出来て便利です。 levelを変更してみる java -jar ../../compiler-latest/compiler.jar –compilation_level ADVANCED_OPTIMIZATIONS –js=dev1.js –js=menu.js –js_output_file=out.js function p(a){var b=[a],c=0;$.b(m,function(g,f){if(f.domain!=a.domain||f.path!=a.path)c++,100<c?reutrn:(b.push(f),console.log(f))});m=b;localStorage.l=JSON.stringify(b);n()}var q=[]; function r(){var a=$(“div#history_thread”),b=”gt;”,c=0;$.b(q,function(a,f){“undefined”!==typeof f.title&&(c++,b+=’gt;gt;’+f.title+”gt;gt;”)});b+=”gt;”;a.c(b);$(“div#history_thread a”).b(function(){$(this).click(function(){var a={domain:$(this).a(“domain”),path:$(this).a(“path”),title:$(this).a(“title”),d:$(this).a(“dat”)};s(a)})});0
ajaxのhttp headerを書き換える。webrequest API | chrome extension
4月 13th, 2012
普通にxhrを弄る場合は http://www.w3.org/TR/XMLHttpRequest/ http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader-method mimetypeなどは beforeSend: function(xhr){ xhr.overrideMimeType(“text/plain;charset=Shift_JIS”); // A xhr.setRequestHeader(“Content-type”,”text/plain;charset=Shift_JIS”); // B }, はAかBで更新できたのですが、この辺はダメで Accept-Charset Accept-Encoding Access-Control-Request-Headers Access-Control-Request-Method Connection Content-Length Cookie Cookie2 Content-Transfer-Encoding Date Expect Host Keep-Alive Origin Referer TE Trailer Transfer-Encoding Upgrade User-Agent Via さてどうしようかと webRequest API の登場です。 http://code.google.com/chrome/extensions/trunk/webRequest.html#event-onBeforeSendHeaders * onBeforeSendHeaders (optionally synchronous) Fires when a request is about to occur and the initial […]