mobile: skip clipping images from webpage

This commit is contained in:
Ammar Ahmed
2023-09-22 10:22:24 +05:00
committed by Ammar Ahmed
parent c1e1a8d1a9
commit 528c0a10de
3 changed files with 45 additions and 31 deletions

File diff suppressed because one or more lines are too long

View File

@@ -96,7 +96,6 @@ export const HtmlLoadingWebViewAgent = React.memo(
<WebView <WebView
ref={webview} ref={webview}
onLoad={() => { onLoad={() => {
console.log("Webview is loaded");
loadHandler.current?.(true); loadHandler.current?.(true);
}} }}
style={{ style={{
@@ -106,6 +105,7 @@ export const HtmlLoadingWebViewAgent = React.memo(
opacity: 0, opacity: 0,
zIndex: -1 zIndex: -1
}} }}
useSharedProcessPool={false}
pointerEvents="none" pointerEvents="none"
onMessage={(event) => { onMessage={(event) => {
try { try {
@@ -123,33 +123,7 @@ export const HtmlLoadingWebViewAgent = React.memo(
console.log("Error handling webview message", e); console.log("Error handling webview message", e);
} }
}} }}
injectedJavaScriptBeforeContentLoaded={` injectedJavaScriptBeforeContentLoaded={script(clipper, premium.current)}
${clipper}
window.addEventListener("load",() => {
function postMessage(type, value) {
if (window.ReactNativeWebView) {
window.ReactNativeWebView.postMessage(
JSON.stringify({
type: type,
value: value
})
);
}
}
if (!globalThis.Clipper.clipPage) {
postMessage("error", globalThis.Clipper.clipPage);
} else {
globalThis.Clipper.clipPage(document,false, {
images: false,
styles: false,
corsProxy: undefined
}).then(result => {
postMessage("html", result);
}).catch(e => {
postMessage("error");
});
}
}, false);`}
onError={() => { onError={() => {
console.log("Error loading page"); console.log("Error loading page");
loadHandler.current?.(); loadHandler.current?.();
@@ -163,4 +137,45 @@ export const HtmlLoadingWebViewAgent = React.memo(
() => true () => true
); );
const script = (clipper, pro) => `
${clipper}
function postMessage(type, value) {
if (window.ReactNativeWebView) {
window.ReactNativeWebView.postMessage(
JSON.stringify({
type: type,
value: value
})
);
}
}
(() => {
try {
const loadFn = () => {
if (!globalThis.Clipper.clipPage) {
postMessage("error", globalThis.Clipper.clipPage);
} else {
globalThis.Clipper.clipPage(document,false, {
images: ${pro},
inlineImages: false,
styles: false,
corsProxy: undefined
}).then(result => {
postMessage("html", result);
}).catch(e => {
postMessage("error");
});
}
};
window.addEventListener("load",loadFn, false);
} catch(e) {
postMessage("error", e.message);
}
})();
`;
HtmlLoadingWebViewAgent.displayName = "HtmlLoadingWebViewAgent"; HtmlLoadingWebViewAgent.displayName = "HtmlLoadingWebViewAgent";

View File

@@ -228,7 +228,6 @@ const ShareView = ({ quicknote = false }) => {
}, [onLoad]); }, [onLoad]);
const onLoad = useCallback(() => { const onLoad = useCallback(() => {
console.log("sending event...");
eSendEvent(eOnLoadNote + "shareEditor", { eSendEvent(eOnLoadNote + "shareEditor", {
id: null, id: null,
content: { content: {
@@ -658,7 +657,7 @@ const ShareView = ({ quicknote = false }) => {
<> <>
{loadingPage ? ( {loadingPage ? (
<> <>
<ActivityIndicator /> <ActivityIndicator color={colors.primary.accent} />
<Text>Preparing web clip...</Text> <Text>Preparing web clip...</Text>
</> </>
) : null} ) : null}