Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Chatterbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
element-hq
Chatterbox
Commits
752caffd
Commit
752caffd
authored
2 years ago
by
RMidhunSuresh
Browse files
Options
Downloads
Patches
Plain Diff
Hide UI on error
parent
d191f966
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/main.ts
+23
-0
23 additions, 0 deletions
src/main.ts
src/parent/iframe.ts
+7
-0
7 additions, 0 deletions
src/parent/iframe.ts
src/parent/parent.ts
+4
-1
4 additions, 1 deletion
src/parent/parent.ts
with
34 additions
and
1 deletion
src/main.ts
+
23
−
0
View file @
752caffd
...
@@ -34,6 +34,7 @@ function shouldStartMinimized(): boolean {
...
@@ -34,6 +34,7 @@ function shouldStartMinimized(): boolean {
}
}
async
function
main
()
{
async
function
main
()
{
hideOnError
();
const
root
=
document
.
querySelector
(
rootDivId
)
as
HTMLDivElement
;
const
root
=
document
.
querySelector
(
rootDivId
)
as
HTMLDivElement
;
if
(
!
root
)
{
if
(
!
root
)
{
throw
new
Error
(
"
No element with id as 'chatterbox' found!
"
);
throw
new
Error
(
"
No element with id as 'chatterbox' found!
"
);
...
@@ -61,6 +62,24 @@ function allowsChild(parent, child) {
...
@@ -61,6 +62,24 @@ function allowsChild(parent, child) {
}
}
}
}
function
hideOnError
()
{
// When an error occurs, log it and then hide everything!
const
handler
=
e
=>
{
if
(
e
.
message
===
"
ResizeObserver loop completed with undelivered notifications.
"
||
e
.
message
===
"
ResizeObserver loop limit exceeded
"
)
{
// see https://stackoverflow.com/a/64257593
e
.
stopImmediatePropagation
();
return
false
;
}
console
.
error
(
e
.
error
??
e
.
reason
);
(
window
as
any
).
sendError
();
return
false
;
};
window
.
addEventListener
(
"
error
"
,
handler
,
true
);
window
.
addEventListener
(
"
unhandledrejection
"
,
handler
,
true
);
}
(
window
as
any
).
sendViewChangeToParent
=
function
(
view
:
"
timeline
"
|
"
account-setup
"
)
{
(
window
as
any
).
sendViewChangeToParent
=
function
(
view
:
"
timeline
"
|
"
account-setup
"
)
{
window
.
parent
?.
postMessage
({
window
.
parent
?.
postMessage
({
action
:
"
resize-iframe
"
,
action
:
"
resize-iframe
"
,
...
@@ -76,4 +95,8 @@ function allowsChild(parent, child) {
...
@@ -76,4 +95,8 @@ function allowsChild(parent, child) {
window
.
parent
?.
postMessage
({
action
:
"
unread-message
"
,
count
},
"
*
"
);
window
.
parent
?.
postMessage
({
action
:
"
unread-message
"
,
count
},
"
*
"
);
};
};
(
window
as
any
).
sendError
=
function
()
{
window
.
parent
?.
postMessage
({
action
:
"
error
"
},
"
*
"
);
};
main
();
main
();
This diff is collapsed.
Click to expand it.
src/parent/iframe.ts
+
7
−
0
View file @
752caffd
...
@@ -42,3 +42,10 @@ export function resizeIframe(data) {
...
@@ -42,3 +42,10 @@ export function resizeIframe(data) {
if
(
height
)
{
iframeElement
.
style
.
height
=
height
;
}
if
(
height
)
{
iframeElement
.
style
.
height
=
height
;
}
if
(
width
)
{
iframeElement
.
style
.
width
=
width
;
}
if
(
width
)
{
iframeElement
.
style
.
width
=
width
;
}
}
}
export
function
removeIframe
()
{
const
iframeElement
=
document
.
querySelector
(
"
.chatterbox-iframe
"
)
as
HTMLIFrameElement
;
iframeElement
?.
remove
();
const
startButton
=
document
.
querySelector
(
"
.start
"
)
as
HTMLDivElement
;
startButton
.
remove
();
}
This diff is collapsed.
Click to expand it.
src/parent/parent.ts
+
4
−
1
View file @
752caffd
import
{
resizeIframe
,
toggleIframe
}
from
"
./iframe
"
;
import
{
resizeIframe
,
toggleIframe
,
removeIframe
}
from
"
./iframe
"
;
import
{
loadStartButton
}
from
"
./load
"
;
import
{
loadStartButton
}
from
"
./load
"
;
import
"
./parent-style.css
"
;
import
"
./parent-style.css
"
;
...
@@ -33,6 +33,9 @@ window.addEventListener("message", event => {
...
@@ -33,6 +33,9 @@ window.addEventListener("message", event => {
case
"
unread-message
"
:
case
"
unread-message
"
:
setUnreadCount
(
event
.
data
.
count
);
setUnreadCount
(
event
.
data
.
count
);
break
;
break
;
case
"
error
"
:
removeIframe
();
break
;
}
}
});
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment