μ¬μ©μ μ€ν¬λ¦½νΈλ₯Ό μ€ννλ λ°©λ²μ λν μμ
κ³νμ μΈμ°μμμ€. λ¬Όλ‘ λ°νμκΉμ§λ μ μ μμ΅λλ€. μΈ κ°μ§ runAt μκ° λͺ¨λμ νΈν κ°λ₯ -- λΉνμ μΌλ‘ document_start
.
μ§κΈκΉμ§μ μ°κ΅¬μ λν΄μλ https://github.com/arantius/greasemonkey/tree/8a255bde1aa6312715740fd0157d582a2d6cb183 μ μ°Έμ‘°
tabs.executeScript()
λ₯Ό νΈμΆνμ¬ κ° μ¬μ©μ μ€ν¬λ¦½νΈλ₯Ό μ€νν©λλ€.μ΄κ²μ μΈ λ²μ μ€ν μκ° λͺ¨λμ λν΄ μλνλ κ²μ κ΄μ°°ν μ΄λ²€νΈκ° μμ§ μλ€λ μ μ μ μΈνκ³ λ "μλ"ν©λλ€. webNavigation
μ onBeforeNavigate
κ° μμ΅λλ€. μ¬μ€ λ무 μ΄λ₯΄λ©° , νμ¬ λ¬Έμκ° μ¬μ ν νμ± μνμΌ λ νμ μ μ (μ΄λ¦μμ μ μ μλ―μ΄) μ€νλ©λλ€. νμ§λ§ λ€μ ν¬μΈνΈλ onCommitted
μ΄κ³ , κ·Έ μμ μμ μμνκΈ°μλ λ무 λ¦μκ³ μΈλΌμΈ μ€ν¬λ¦½νΈκ° μ΄λ―Έ μ€νλμμ΅λλ€.
μ‘°μ¬νλ €λ©΄:
webRequest
λμ webNavigation
. μμ μκ°μ μ²λ¦¬ν μ μμ΅λκΉ?μ¬: https://bugzilla.mozilla.org/show_bug.cgi?id=1332273#c8
blobμ (λ°±κ·ΈλΌμ΄λμμ) μ μ₯νκ³ λμ€μ (λ§) ν΄λΉ URLμ κ°μ Έμ€κ³ ν΄λΉ URLμ μ½ν μΈ μ€ν¬λ¦½νΈμ (λκΈ°μ μΌλ‘) μ λ¬ν μ μκΈ°λ₯Ό μνμ§λ§ μ΄λ¬ν μμ μ μνν λ°©λ²μ΄ μμ΅λλ€.
λͺ¨λ μΈλΆ μ¬νμ μ§μ ν΄κ²°νμ§λ μμμ§λ§ λ°°κ²½ νμ΄μ§κ° IndexedDBμ blobμ μ μ₯ν μ μλ€κ³ μκ°ν©λλ€. κ·Έλ° λ€μ μμ μ URL.createObjectURL()μ ν΅ν΄ blob URIλ‘ λ³ννκ³ κ°μμ λκΈ° κ΅¬μ± APIμ μ λ¬ν λ€μ μλ§λ ν΅ν΄ λ‘λ
Firefoxμ κ°μΈ λΈλΌμ°μ§ λͺ¨λ λΉνμ±ν λμ§ μμ΅λκΉ?
κ·Έκ²μ΄ λ°°κ²½ μ€ν¬λ¦½νΈμ μν₯μ λ―ΈμΉμ§ μλλ€κ³ μκ°ν©λκΉ?
μ΄κ²μ document_start
μμ μ€νλκ³ λ€μκ³Ό κ°μ΄ 보μ΄λ μ½ν
μΈ μ€ν¬λ¦½νΈλ₯Ό μ¬μ©νμ¬ κ°λ₯ν©λλ€. (μ΄λ―Έ λ‘λλ νμμλ μλνμ§ μμ μ μμΌλ―λ‘ jQueryλ₯Ό μ¬μ©νμμμ€)
// execute `document_start` scripts here...
document.addEventListener("DOMContentLoaded", event => {
// execute `document_end` scripts here...
});
window.addEventListener("load", event => {
// execute `document_idle` scripts here...
});
λλ μ΄μ κ°μ κ²: (μ€λ₯κ° λ°μνκΈ° μ¬μΈ μ μμ)
let run = [false, false, false];
document_start();
if (document.readyState === "complete") {
document_idle();
} else if (document.readyState === "interactive") {
document_end();
}
document.onreadystatechange = () => {
switch (document.readyState) {
case "loading": break;
case "interactive": document_end();
case "complete": document_idle();
}
};
function document_start() {
if (run[0]) return;
run[0] = true;
// execute `document_start` scripts here...
}
function document_end() {
if (!run[0]) document_start();
if (run[1]) return;
run[1] = true;
// execute `document_end` scripts here...
}
function document_idle() {
if (!run[1]) document_end();
if (run[2]) return;
run[2] = true;
// execute `document_idle` scripts here...
}
λ λ€λ₯Έ λ°©λ²μ κ°κ° λ€λ₯Έ μκ°μ μ€νλλ μΈ κ°μ κ°λ³ μ½ν
μΈ μ€ν¬λ¦½νΈλ₯Ό μ¬μ©νλ κ²μ
λλ€.
μ΄λ₯Ό μν΄ manifest.json
μλ λ€μμ΄ ν¬ν¨λ©λλ€. (μλ§λ μλνλλ‘ λ³΄μ₯(κ²½ν© μ‘°κ±΄μ΄ μμ μ μμ))
"content_scripts": [
{
"matches": ["<all_urls>"],
"run_at": "document_start",
"js": ["document_start_handler.js"]
},
{
"matches": ["<all_urls>"],
"run_at": "document_end",
"js": ["document_end_handler.js"]
},
{
"matches": ["<all_urls>"],
"run_at": "document_idle",
"js": ["document_idle_handler.js"]
}
]
μ€λ₯κ° κ°μ₯ μ μ λ°©λ²μΈ jQueryλ₯Ό μ¬μ©νλ κ²λ κ°λ₯νμ§λ§ μ΄ λͺ¨λ κ²μ κ΄λ²μν ν
μ€νΈκ° νμν©λλ€. (λ€μ document_start
μμ μ€νλμ§λ§ jQueryμ ν¨κ» λ²λ€λ‘ μ 곡λμ΄μΌ ν¨)
function document_start() {
// execute `document_start` scripts here...
}
function document_end() {
// execute `document_end` scripts here...
}
function document_idle() {
// execute `document_idle` scripts here...
}
// Use jQuery to execute all the functions:
document_start();
// `$(document).ready(document_end)` is deprecated since 3.0
$(document_end);
// jQuery used to have a method for this: `$(window).load(document_idle)`
if (document.readyState === "complete") {
document_idle();
} else {
$(window).on("load", document_idle);
}
μ°μ¬μ§ λλ‘ μ΄ λ¬Έμ λ λ무 κ΄λ²μν©λλ€. λ μ½κ² μΆμ ν μ μλλ‘ μ΄ λ¬Έμ λ₯Ό λ³λμ λ¬Έμ λ‘ λΆν νκ³ μμ΅λλ€.