短期專案進行已經過 10 天了。
專案的大致架構已經出來。
但是,卻面臨了在 Chrome Extension 中無法串接 Facebook API 的情況。
啊... 真希望趕快解決... 救救我...
總算暫時解決了。
並沒有另外進行 Facebook 登入。(根據 Google 搜尋的結果)有人分析了 Facebook 查詢並上傳了內容。
我只抓取了該部分進行處理。
以下是處理結果。
另外,從既有成員南斗鉉(音譯)先生那裡獲得了關於提取文章內縮圖資訊的方法。
明天打算進行利用文章連結提取文章縮圖的部分。
預計按照以下順序進行。
1. HTML 解析
2. 透過 Meta 標籤分析獲取字元編碼 ( UTF-8, EUC-KR ... etc )
3. 使用該字元編碼重新解析
4. 透過正規表示式移除 <script>、<style>
5. 透過正規表示式移除 <body> 內的 <h2>、<span>、<p>
6. 在乾淨的 body 內,儲存文字區塊與其長度
7. 排序
8. 從排序後的文字中,將突然變少的部分開始全部刪除
9. 尋找文字較多的區塊附近的 img 標籤並取得 href 值
以上是理論上...
明天一定要試試看...
P.S. 我發現自己對 Chrome Extension 的理解度非常不足。嘗試直接將既有的 Facebook API 貼到 Extension 時,被 CSP 擋住了... 感覺我盯著下面這段話分析了兩個小時。
Content Security Policy directive: "script-src 'self' chrome-extension-resource:".
結果確認該部分無法直接使用...
關於 Facebook 登入,我現在還是不太清楚。如果有誰知道的話... 麻煩留言指教。 (_ _)
非常感謝。
咦...
展開
早上起床後,帶著渾渾噩噩的精神重新看了 Google 文件。
(如何遵守內容安全政策)
首先為了遵守規定,必須了解 Google 擴充功能的 CSP 是什麼。
我竟然沒看到就寫在下面。
What is the CSP for Chrome Apps?
The content security policy for Chrome Apps restricts you from doing the following:
- You can’t use inline scripting in your Chrome App pages. The restriction bans both <script> blocks and event handlers (<button onclick="...">).
- You can’t reference any external resources in any of your app files (except for video and audio resources). You can’t embed external resources in an iframe.
-
You can’t use string-to-JavaScript methods like
eval()andnew Function().
整理以上內容如下:
_Chrome App 的內容安全政策。
1. 不能在 HTML 頁面使用 inline scripting。
2. 不能參照任何外部資源。此外,也不能在 iframe 內插入外部資源。
3. 無法使用將字串函數化的 eval() 等函數。
啊... 結果是被強制要求只能使用內部數據。看得出有從根源上封鎖 XSS 漏洞的努力。
搜尋 XSS 時,出現了很多關於網頁駭客攻擊的資訊。
然後看下面...
Your Chrome App can only refer to scripts and objects within your app, with the exception of media files (apps can refer to video and audio outside the package). Chrome extensions will let you relax the default Content Security Policy; Chrome Apps won’t.
幸好... 雖然說 Chrome 擴充功能可以放寬,但 Chrome App 卻說沒這種事。
All JavaScript and all resources should be local (everything gets packaged in your Chrome App).
建議所有 JavaScript 或所有資源都應該是本地數據。
那麼真的真的沒有方法可以使用外部資源嗎...
往下看還有...
Use templating libraries
Use a library that offers precompiled templates and you’re all set. You can still use a library that doesn’t offer precompilation, but it will require some work on your part and there are restrictions.
You will need to use sandboxing to isolate any content that you want to do ‘eval’ things to. Sandboxing lifts CSP on the content that you specify. If you want to use the very powerful Chrome APIs in your Chrome App, your sandboxed content can't directly interact with these APIs (see Sandbox local content ).
Access remote resources
You can fetch remote resources via
XMLHttpRequest
and serve them via
blob:
,
data:
, or
filesystem:
URLs (see
Referencing external resources
).
Video and audio can be loaded from remote services because they have good fallback behavior when offline or under spotty connectivity.
Embed web content
Instead of using an iframe, you can call out to an external URL using a webview tag (see Embed external web pages ).
竟然有三種方法。
1. 利用 Sandbox 與 Chrome API 進行主頁面與沙盒頁面的交流
2. 透過 XMLHttpRequest 使用 blob 等參照外部資源。(腳本似乎不行)
3. 使用 iframe 處理。
理論上寫著利用這三種方法可以進行外部資源參照。
不過,關於能否使用外部腳本的部分沒有提到,所以我不太清楚。
以後有機會的話,會試著利用這三種方式嘗試是否能從外部匯入腳本。
現在因為還有下一個目標,所以 Pass...