๋ฐ์ํ
[ ๋ฌธ์ ]
- ํ์ด๋จธ๋ฅผ ์ ์ฉํ๋ setInterval์ด ๊ฐํ์ ์ผ๋ก ์คํ๋์ง ์์
- ์๋ก์ด window๋ฅผ ์ด์์ ๋, background.js๊ฐ ์ฌ ์คํ๋๋ฉด์, tabId๊ฐ โโ๋ก ์ด๊ธฐํ ๋จ
setInterval
Manifest V3๋ก ์ด์ ๋๋ฉด์, chrome alarms API๋ก ๋ณ๊ฒฝ
https://developer.chrome.com/docs/extensions/mv3/migrating_to_service_workers/#alarms
chrome.alarms.create({ when:Date.now(), periodInMinutes: 1/60});
chrome.alarms.onAlarm.addListener(() => {
// Do Action
});
- alarms ์ฌ์ฉ์ ์ํด, Manifest์ Permission โalarmsโ ์ถ๊ฐ
- when: ์์ ์๊ฐ periodInMinutes: ์ด๋ฒคํธ ๋ฐ์ ๊ฐ๊ฒฉ. ์ค์ ํ์ง ์์ ์, when์ ๋ฐ๋ผ ํ๋ฒ๋ง ๋์
New window ์ด๊ธฐํ ๋ฌธ์
Chrome์ Local Storage์ ์ ์ฅ
chrome.storage.local.get(['docongTab'],(result)=>{
chrome.tabs.get(result.docongTab, (tab)=>{
if(tab.url.includes("j6s003.p.ssafy.io")){
chrome.scripting.executeScript({
target: {tabId: result.docongTab},
func: ()=>{return localStorage["persist:root"];}
}, (result)=>{
timerStatus = JSON.parse(JSON.parse(result[0].result).user).userTimer;
if(timerStatus.status == "play"){
timer = true;
playTimer(timerStatus);
} else {
timer = false;
chrome.action.setIcon({
path:"img/icon16.png"
});
}
});
}
})
})
- localStorage์ ์ ์ฅํ์ฌ, ๋ชจ๋ Window์์ ๋์ผํ ๊ฐ์ ๊ฐ์ง ์ ์๋๋ก ์ค์
- ์ ์ฅ๋์ด ์๋ tabID์ URL์ด Docong์ด์ด์ผ๋ง ํ์ด๋จธ Logic ์คํ
๋ฐ์ํ
'๐ป ๊ฐ๋ฐ ์ผ์ง > FrontEnd' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Chrome Extension] ์น ํ์ด์ง ์ฐ๋ ํ์ด๋จธ ๊ตฌํํ๊ธฐ (0) | 2022.03.17 |
---|---|
[Chrome Extension] ํญ ์ ์ด ๊ธฐ๋ฅ ๋ง๋ค๊ธฐ (0) | 2022.03.17 |
[Chrome Extension] Chrome Storage๋ฅผ ํ์ฉํ Extension ๋ง๋ค๊ธฐ (0) | 2022.03.16 |
๋ฐ์ํ
[ ๋ฌธ์ ]
- ํ์ด๋จธ๋ฅผ ์ ์ฉํ๋ setInterval์ด ๊ฐํ์ ์ผ๋ก ์คํ๋์ง ์์
- ์๋ก์ด window๋ฅผ ์ด์์ ๋, background.js๊ฐ ์ฌ ์คํ๋๋ฉด์, tabId๊ฐ โโ๋ก ์ด๊ธฐํ ๋จ
setInterval
Manifest V3๋ก ์ด์ ๋๋ฉด์, chrome alarms API๋ก ๋ณ๊ฒฝ
https://developer.chrome.com/docs/extensions/mv3/migrating_to_service_workers/#alarms
chrome.alarms.create({ when:Date.now(), periodInMinutes: 1/60});
chrome.alarms.onAlarm.addListener(() => {
// Do Action
});
- alarms ์ฌ์ฉ์ ์ํด, Manifest์ Permission โalarmsโ ์ถ๊ฐ
- when: ์์ ์๊ฐ periodInMinutes: ์ด๋ฒคํธ ๋ฐ์ ๊ฐ๊ฒฉ. ์ค์ ํ์ง ์์ ์, when์ ๋ฐ๋ผ ํ๋ฒ๋ง ๋์
New window ์ด๊ธฐํ ๋ฌธ์
Chrome์ Local Storage์ ์ ์ฅ
chrome.storage.local.get(['docongTab'],(result)=>{
chrome.tabs.get(result.docongTab, (tab)=>{
if(tab.url.includes("j6s003.p.ssafy.io")){
chrome.scripting.executeScript({
target: {tabId: result.docongTab},
func: ()=>{return localStorage["persist:root"];}
}, (result)=>{
timerStatus = JSON.parse(JSON.parse(result[0].result).user).userTimer;
if(timerStatus.status == "play"){
timer = true;
playTimer(timerStatus);
} else {
timer = false;
chrome.action.setIcon({
path:"img/icon16.png"
});
}
});
}
})
})
- localStorage์ ์ ์ฅํ์ฌ, ๋ชจ๋ Window์์ ๋์ผํ ๊ฐ์ ๊ฐ์ง ์ ์๋๋ก ์ค์
- ์ ์ฅ๋์ด ์๋ tabID์ URL์ด Docong์ด์ด์ผ๋ง ํ์ด๋จธ Logic ์คํ
๋ฐ์ํ
'๐ป ๊ฐ๋ฐ ์ผ์ง > FrontEnd' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Chrome Extension] ์น ํ์ด์ง ์ฐ๋ ํ์ด๋จธ ๊ตฌํํ๊ธฐ (0) | 2022.03.17 |
---|---|
[Chrome Extension] ํญ ์ ์ด ๊ธฐ๋ฅ ๋ง๋ค๊ธฐ (0) | 2022.03.17 |
[Chrome Extension] Chrome Storage๋ฅผ ํ์ฉํ Extension ๋ง๋ค๊ธฐ (0) | 2022.03.16 |