Popular Posts
abap naming rule 命名規則 報表程式(以列表格式輸出資料分析):Yaxxxxxx或Zaxxxxxx。用應用程式區的分類字母替換a。 任何有效字元替換x。注意SAP報表程式遵守相似的命名約定:Raxxxxxx。 任何其他ABAP/4程式(培訓程式或事務程式):SAPMYxxx或SAPMZxxx... IDES 4.7 Installation 電腦名稱不能使用特殊名稱(bin/etc/var ...) 網路卡-> File and Printer Sharing for Microsoft Networks ->網路應用程式的資料輸送量最大化 安裝jdk1.4 (不升級) 設置JAVA_HOME ... Data type 資料類型 預設大小 大小 初始值 輸出長度 輸出定位 說明 C 1 1-65535 SPACE 字串長度 LEFT-JUSTIFIED 字...
Stats
Reset code intelligence on eclipse ADT bundle
Window > Preference >
General > Keys
Search word completion
Click Unbind Command button
Search content assist
Change binding to Alt + /
Execute script loaded on page context

Chrome extension works on separate sandbox environment while it running. This means extension can't call script functions that loaded on page context. Due to a unexpected reason, I found a method that allow extension call functions loaded on page context from extension.

scenario

Target page
There is script function helloPage on target page. Page won't execute this function when page loaded.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript">
    function helloPage() {
        for ( var i = 0; i < 10; i++) {
            var div = document.createElement('div');
            div.innerHTML = 'hello page ' + i;
            document.body.appendChild(div);
        }
    }
</script>
</head>
<body>
    <h3>Test Page</h3>
</body>
</html>
manifest.json
In manifest, extension will execute jQuery, init.js, callable.js when page is loaded, and callable.js is allowed access from web.
{
    "manifest_version": 2,
    "name": "Context test",
    "description": "Context test",
    "version": "0.3.1",
    "permissions": ["tabs", "http://*/*", "https://*/*"],
    "content_scripts": [{
        "matches": ["http://*/*", "https://*/*", "file://*/*"],
        "js": ["js/jquery-1.9.1.min.js", "js/init.js", "js/callable.js"],
        "run_at": "document_end"
    }],
    "web_accessible_resources": ["js/callable.js"]
}
init.js
This script define a function that execute a callback function like delegation. When page loaded, callable.js will be loaded by ajax call.
function dowork($callback) {
    console.log('Begin dowork at ' + new Date());
    if($callback && typeof ($callback) == 'function') $callback();
}
$(function () {
    console.log('Begin init.js at ' + new Date());
    dowork(function () {
        console.log('Dynamic load callable.js at ' + new Date());
        $.ajax({
            async: false,
            url: chrome.extension.getURL('js/callable.js'),
            dataType: 'script'
        });
    });
});
callable.js
In callback.js, it checks jQuery is loaded (should be exist in extension context) or not and print message on console. Then try to execute helloPage on page context.
(function () {
    console.log('Run callable.js at ' + new Date());
    console.log('Check jQuery status (loaded in extension context) : ' + (typeof ($) != 'undefined').toString());
    if(typeof (helloPage) == 'undefined') {
        console.log('helloPage not exist');
    } else {
        console.log('Execute page function "helloPage()"');
        helloPage();
    }
})();
Result
Afterwords

Althouth this could inject script into page context, but this may cause some security issue. And it was not the result that I expected, I hope this will be fixed in the future.