Skip to content

Commit

Permalink
Better base64 encode, utf8 support
Browse files Browse the repository at this point in the history
  • Loading branch information
exentrich committed Sep 24, 2024
1 parent 7f3da7e commit 331b901
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
11 changes: 9 additions & 2 deletions src/co/common/webview/browser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import s from './browser.module.styl'
import React, { useEffect } from 'react'
import React, { useEffect, useMemo } from 'react'
import { PREVIEW_URL } from '~data/constants/app'

export default function WebViewBrowser({ src, forwardedRef, className='', onError, ...etc }) {
Expand All @@ -12,6 +12,13 @@ export default function WebViewBrowser({ src, forwardedRef, className='', onErro
return ()=>window.removeEventListener('message', onMessage)
}, [onError])

const base64 = useMemo(()=>
btoa(
String.fromCharCode(...new TextEncoder('utf-8').encode(src))
),
[src]
)

return (
<iframe
plugins='true'
Expand All @@ -20,7 +27,7 @@ export default function WebViewBrowser({ src, forwardedRef, className='', onErro
{...etc}
ref={forwardedRef}
className={s.iframe + ' ' + className}
src={`${PREVIEW_URL}/web/${btoa(src)}`}
src={`${PREVIEW_URL}/web/${base64}`}
onError={onError} />
)
}
Loading

0 comments on commit 331b901

Please sign in to comment.