Skip to content

Commit da659c8

Browse files
committed
added context menu
1 parent 0047abb commit da659c8

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/extension/background.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,27 @@ chrome.tabs.onRemoved.addListener(tabId => {
145145
// delete the tab from the tabsObj
146146
delete tabsObj[tabId];
147147
});
148+
149+
// when react time travel is installed
150+
// create a context menu that will open our devtools in a new window
151+
chrome.runtime.onInstalled.addListener(() => {
152+
chrome.contextMenus.create({
153+
id: 'react-time-travel',
154+
title: 'React Time Travel',
155+
contexts: ['page', 'selection', 'image', 'link'],
156+
});
157+
});
158+
159+
// when context menu is clicked, listen for the menuItemId,
160+
// if user clicked on react-time-travel, open the devtools window
161+
chrome.contextMenus.onClicked.addListener(({ menuItemId }) => {
162+
const options = {
163+
type: 'panel',
164+
left: 0,
165+
top: 0,
166+
width: 380,
167+
height: window.screen.availHeight,
168+
url: chrome.runtime.getURL('panel.html'),
169+
};
170+
if (menuItemId === 'react-time-travel') chrome.windows.create(options);
171+
});

src/extension/build/devtools.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
chrome.devtools.panels.create('React Time-Travel', null, 'panel.html', () => {
2-
});
1+
chrome.devtools.panels.create('React Time Travel', null, 'panel.html', () => {});

src/extension/build/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "React Time-Travel",
2+
"name": "React Time Travel",
33
"version": "1.0",
44
"devtools_page": "devtools.html",
55
"description": "A Chrome extension that helps debug React by memorizing the state of components with every render.",

0 commit comments

Comments
 (0)