Greasemonkey: WebExt: μ„Έ 번 λͺ¨λ‘ runAt μ‹œκ°„μ— 슀크립트 μ‹€ν–‰

에 λ§Œλ“  2017λ…„ 02μ›” 27일  Β·  6μ½”λ©˜νŠΈ  Β·  좜처: greasemonkey/greasemonkey

μ‚¬μš©μž 슀크립트λ₯Ό μ‹€ν–‰ν•˜λŠ” 방법에 λŒ€ν•œ μž‘μ—… κ³„νšμ„ μ„Έμš°μ‹­μ‹œμ˜€. λ¬Όλ‘  λŸ°νƒ€μž„κΉŒμ§€λŠ” μ•Œ 수 μ—†μŠ΅λ‹ˆλ‹€. μ„Έ 가지 runAt μ‹œκ°„ λͺ¨λ‘μ™€ ν˜Έν™˜ κ°€λŠ₯ -- λΉ„νŒμ μœΌλ‘œ document_start .

μ§€κΈˆκΉŒμ§€μ˜ 연ꡬ에 λŒ€ν•΄μ„œλŠ” https://github.com/arantius/greasemonkey/tree/8a255bde1aa6312715740fd0157d582a2d6cb183 을 μ°Έμ‘°

  • ν•˜λ‚˜μ˜ λ°°κ²½ 슀크립트λ₯Ό μ‚¬μš©ν•˜μ‹­μ‹œμ˜€. (μŠ€ν¬λ¦½νŠΈκ°€ μ €μž₯된 μ €μž₯μ†Œ/λͺ¨λ“  API에 μ•‘μ„ΈμŠ€ν•  수 μžˆμœΌλ―€λ‘œ μ‹€ν–‰ν•  슀크립트의 λ‚΄μš©μ„ μ•Œ 수 μžˆμŠ΅λ‹ˆλ‹€.)
  • μ΄‰λ°œμ‹œν‚¬ 무언가( 무엇? )λ₯Ό κ΄€μ°°ν•˜μ‹­μ‹œμ˜€.
  • .. tabs.executeScript() λ₯Ό ν˜ΈμΆœν•˜μ—¬ 각 μ‚¬μš©μž 슀크립트λ₯Ό μ‹€ν–‰ν•©λ‹ˆλ‹€.

이것은 μ„Έ 번의 μ‹€ν–‰ μ‹œκ°„ λͺ¨λ‘μ— λŒ€ν•΄ μž‘λ™ν•˜λŠ” 것을 κ΄€μ°°ν•œ μ΄λ²€νŠΈκ°€ 아직 μ—†λ‹€λŠ” 점을 μ œμ™Έν•˜κ³ λŠ” "μž‘λ™"ν•©λ‹ˆλ‹€. webNavigation 의 onBeforeNavigate κ°€ μžˆμŠ΅λ‹ˆλ‹€. 사싀 λ„ˆλ¬΄ 이λ₯΄λ©° , ν˜„μž¬ λ¬Έμ„œκ°€ μ—¬μ „νžˆ ν™œμ„± μƒνƒœμΌ λ•Œ 탐색 전에 (μ΄λ¦„μ—μ„œ μ•Œ 수 μžˆλ“―μ΄) μ‹€ν–‰λ©λ‹ˆλ‹€. ν•˜μ§€λ§Œ λ‹€μŒ ν¬μΈνŠΈλŠ” onCommitted 이고, κ·Έ μ‹œμ μ—μ„œ μ‹œμž‘ν•˜κΈ°μ—λŠ” λ„ˆλ¬΄ λŠ¦μ—ˆκ³  인라인 μŠ€ν¬λ¦½νŠΈκ°€ 이미 μ‹€ν–‰λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

wontfix

λͺ¨λ“  6 λŒ“κΈ€

μ‘°μ‚¬ν•˜λ €λ©΄:

  • κ΄€μ°° webRequest λŒ€μ‹  webNavigation . μ‹œμž‘ μ‹œκ°„μ— μ²˜λ¦¬ν•  수 μžˆμŠ΅λ‹ˆκΉŒ?
  • λͺ¨λ“  νŽ˜μ΄μ§€μ— λŒ€ν•΄ document_startμ—μ„œ ν•˜λ‚˜μ˜ webext μ½˜ν…μΈ  슀크립트λ₯Ό μ‚½μž…ν•˜μ‹­μ‹œμ˜€. λ™κΈ°μ‹μœΌλ‘œ μ‹€ν–‰ν•  슀크립트λ₯Ό μ–΄λ–»κ²Œλ“  μ•Œλ„λ‘ ν•©λ‹ˆλ‹€. (λΉ„λ™κΈ°λŠ” 무엇이든 μ‹œμž‘ μ‹œκ°„μ„ μ§€λ‚˜λ„λ‘ 밀어뢙이기 λ•Œλ¬Έμž…λ‹ˆλ‹€.)

재: 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);
}

쓰여진 λŒ€λ‘œ 이 λ¬Έμ œλŠ” λ„ˆλ¬΄ κ΄‘λ²”μœ„ν•©λ‹ˆλ‹€. 더 μ‰½κ²Œ 좔적할 수 μžˆλ„λ‘ 이 문제λ₯Ό λ³„λ„μ˜ 문제둜 λΆ„ν• ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€.

2525, #2526

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰