-
Notifications
You must be signed in to change notification settings - Fork 2
Feature(extension): 익스텐션 윈도우 체류시간 측정 작업 #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,10 +1,32 @@ | ||||||
| import * as React from 'react'; | ||||||
| import { useState } from 'react'; | ||||||
| import logo from './logo.png'; | ||||||
| // import './App.css'; | ||||||
| import ModalPop from '@components/modalPop/ModalPop'; | ||||||
| import { useEffect, useState } from 'react'; | ||||||
|
|
||||||
| const App = () => { | ||||||
| return <ModalPop />; | ||||||
| const [url, setUrl] = useState(''); | ||||||
|
|
||||||
| useEffect(() => { | ||||||
| chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { | ||||||
| const activeTab = tabs[0]; | ||||||
| if (activeTab?.url) { | ||||||
| setUrl(activeTab.url); | ||||||
| console.log('📌 URL:', activeTab.url); | ||||||
|
|
||||||
| chrome.storage.local.set({ bookmarkedUrl: activeTab.url }, () => { | ||||||
| console.log('저장'); | ||||||
| }); | ||||||
| } | ||||||
| }); | ||||||
| }, []); | ||||||
| return ( | ||||||
| <div> | ||||||
| <h1 className="text-lg font-bold">📎 북마크 저장!</h1> | ||||||
| <p className="mt-2 break-words text-sm">{url}</p> | ||||||
| <ModalPop urlInfo={url} />; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JSX 구문 오류를 수정해주세요. JSX 요소 뒤에 세미콜론이 잘못 위치했습니다. 다음과 같이 수정해주세요: - <ModalPop urlInfo={url} />;
+ <ModalPop urlInfo={url} />📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| </div> | ||||||
| ); | ||||||
| }; | ||||||
|
|
||||||
| export default App; | ||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,15 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('bg'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (message.type === 'PAGE_DURATION') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { url, duration } = message.payload; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(`🌐 ${url} 체류시간: ${duration}초`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // optionally alert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chrome.notifications.create({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'basic', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| iconUrl: 'icon48.png', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title: '체류시간 측정', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| message: `${new URL(url).hostname}에서 ${duration}초 머물렀어요!`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+2
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 에러 처리 및 입력 검증 추가 필요 메시지 핸들러에서 다음 사항들이 개선되어야 합니다:
다음과 같이 개선하는 것을 권장합니다: chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === 'PAGE_DURATION') {
- const { url, duration } = message.payload;
+ const { url, duration } = message.payload || {};
+
+ if (!url || !duration) {
+ console.error('Invalid payload structure');
+ return;
+ }
+
console.log(`🌐 ${url} 체류시간: ${duration}초`);
// optionally alert
- chrome.notifications.create({
- type: 'basic',
- iconUrl: 'icon48.png',
- title: '체류시간 측정',
- message: `${new URL(url).hostname}에서 ${duration}초 머물렀어요!`,
- });
+ try {
+ const hostname = new URL(url).hostname;
+ chrome.notifications.create({
+ type: 'basic',
+ iconUrl: 'icon48.png',
+ title: '체류시간 측정',
+ message: `${hostname}에서 ${duration}초 머물렀어요!`,
+ });
+ } catch (error) {
+ console.error('Failed to create notification:', error);
+ }
}
});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Comment on lines
+2
to
+15
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 타입을 별도 파일로 분리해두면 재사용성과 안정성이 높아지고, IDE 자동완성도 더 잘 작동해서 분리해두면 좋을 것 같습니다! // types/messages.ts
export interface PageDurationMessage {
type: 'PAGE_DURATION';
payload: {
url: string;
duration: number;
};
}
export type ExtensionMessage = PageDurationMessage;// background.ts
import type { ExtensionMessage } from '@/types/messages';
chrome.runtime.onMessage.addListener(
(message: ExtensionMessage, sender, sendResponse) => {
if (message.type === 'PAGE_DURATION') {
const { url, duration } = message.payload;
// 안전하게 로직 처리 가능
}
}
); |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,7 +9,23 @@ import { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from '@pinback/design-system/ui'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ModalHeader from './ModalHeader'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { POP_TEXTAREA_MAX_LENGTH } from '@constants/index'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ModalPop = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| interface ModalPopProps { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| urlInfo?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ModalPop = (urlInfo: ModalPopProps) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 매개변수 구조분해 문법 오류 수정 필요 함수 매개변수에서 props 구조분해가 잘못되었습니다. 다음과 같이 수정해야 합니다: -const ModalPop = (urlInfo: ModalPopProps) => {
+const ModalPop = ({ urlInfo }: ModalPopProps) => {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 현재 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const handleSave = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chrome.runtime.sendMessage( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'SAVE_BOOKMARK', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| payload: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| url: { urlInfo }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (response) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('✅ 응답 받음:', response); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+16
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 에러 처리 및 payload 구조 개선 필요 handleSave 함수에서 다음 사항들이 개선되어야 합니다:
다음과 같이 개선하는 것을 권장합니다: const handleSave = () => {
chrome.runtime.sendMessage(
{
type: 'SAVE_BOOKMARK',
payload: {
- url: { urlInfo },
+ url: urlInfo,
},
},
(response) => {
- console.log('✅ 응답 받음:', response);
+ if (chrome.runtime.lastError) {
+ console.error('메시지 전송 실패:', chrome.runtime.lastError);
+ } else {
+ console.log('✅ 응답 받음:', response);
+ }
}
);
};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [formState, setFormState] = useState({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| date: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dateError: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -86,7 +102,12 @@ const ModalPop = () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <CommonBtn text="저장하기" size="large" type="green" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <CommonBtn | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| text="저장하기" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| size="large" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type="green" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClick={handleSave} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+105
to
+110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 버튼 타입 속성 추가 필요 리트리빙된 학습 내용에 따르면, React 컴포넌트에서 button 요소에는 항상 type 속성을 명시해야 합니다. CommonBtn 컴포넌트에 type="button" 속성을 추가하는 것을 권장합니다: <CommonBtn
+ type="button"
text="저장하기"
size="large"
type="green"
onClick={handleSave}
/>참고: 만약 CommonBtn 컴포넌트가 내부적으로 button 요소를 렌더링한다면, 해당 컴포넌트에서 type 속성을 처리하도록 해야 합니다.
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| console.log('Hello from content script!'); | ||
| console.log('Hello from content!'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
에러 핸들링 추가를 권장합니다.
chrome.tabs.query와 chrome.storage.local.set 작업에 에러 핸들링이 필요합니다.
다음과 같이 에러 핸들링을 추가하는 것을 권장합니다:
useEffect(() => { chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { const activeTab = tabs[0]; if (activeTab?.url) { setUrl(activeTab.url); console.log('📌 URL:', activeTab.url); - chrome.storage.local.set({ bookmarkedUrl: activeTab.url }, () => { - console.log('저장'); - }); + chrome.storage.local.set({ bookmarkedUrl: activeTab.url }, () => { + if (chrome.runtime.lastError) { + console.error('저장 실패:', chrome.runtime.lastError); + } else { + console.log('저장 완료'); + } + }); } }); }, []);📝 Committable suggestion
🤖 Prompt for AI Agents