generated from abhijithvijayan/web-extension-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added notify feature for each recorded action
Signed-off-by: aryangupta701 <[email protected]>
- Loading branch information
1 parent
8e0611a
commit 3a7fa5c
Showing
5 changed files
with
89 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
"short_name": "ZAP", | ||
|
||
"permissions": [ | ||
"notifications", | ||
"tabs", | ||
"cookies", | ||
"storage" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const ZEST_CLIENT_SWITCH_TO_FRAME = 'ZestClientSwitchToFrame'; | ||
export const ZEST_CLIENT_ELEMENT_CLICK = 'ZestClientElementClick'; | ||
export const ZEST_CLIENT_ELEMENT_SEND_KEYS = 'ZestClientElementSendKeys'; | ||
export const ZEST_CLIENT_LAUNCH = 'ZestClientLaunch'; | ||
export const ZEST_CLIENT_ELEMENT_CLEAR = 'ZestClientElementClear'; | ||
export const ZEST_CLIENT_WINDOW_CLOSE = 'ZestClientWindowClose'; | ||
export const ZEST_CLIENT_ELEMENT_MOUSE_OVER = 'ZestClientMouseOverElement'; | ||
export const DEFAULT_WINDOW_HANDLE = 'windowHandle1'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Browser, {Notifications} from 'webextension-polyfill'; | ||
import { | ||
ZEST_CLIENT_ELEMENT_CLICK, | ||
ZEST_CLIENT_ELEMENT_SEND_KEYS, | ||
ZEST_CLIENT_SWITCH_TO_FRAME, | ||
} from './constants'; | ||
|
||
function clearNotification(notifyId: string): void { | ||
setTimeout(() => { | ||
Browser.notifications.clear(notifyId); | ||
}, 2000); | ||
} | ||
|
||
export const raiseNotification = async (data: string): Promise<void> => { | ||
try { | ||
let title: string; | ||
let message: string; | ||
const statement = JSON.parse(data); | ||
switch (statement.elementType) { | ||
case ZEST_CLIENT_ELEMENT_CLICK: | ||
title = 'Click Recorded'; | ||
message = `Path Type: ${statement.type} Element: ${statement.element}`; | ||
break; | ||
case ZEST_CLIENT_ELEMENT_SEND_KEYS: | ||
title = `Input Recorded -> ${statement.value}`; | ||
message = `Path Type: ${statement.type} Element: ${statement.element}`; | ||
break; | ||
case ZEST_CLIENT_SWITCH_TO_FRAME: | ||
title = 'Frame Switch Recorded'; | ||
message = `Frame Index: ${statement.frameIndex}`; | ||
break; | ||
default: | ||
// Don't raise notifcation | ||
return; | ||
} | ||
const options: Notifications.CreateNotificationOptions = { | ||
type: 'basic', | ||
title, | ||
iconUrl: '../assets/icons/zap32x32.png', | ||
message, | ||
}; | ||
|
||
const notifyId = await Browser.notifications.create(options); | ||
clearNotification(notifyId); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
}; |