youtube - How to disable the Page Visibility API of react native webview? - Stack Overflow
I am trying to create a simple Brave-like browser that can play YouTube videos when the app is in the background. I've tried many other options, but I think the best way is to disable the page visibility API of the webview itself so that it does not send the app visibility signal to the website. I've tried to inject JS code to do this, but it's not working. Is there any other way in React Native, like customizing the webview native code to disable the visibility API? I am not using Expo. It's a React Native CLI project.
import React from 'react';
import { StyleSheet, View } from 'react-native';
import { WebView } from 'react-native-webview';
const App = () => {
const injectedJavaScriptBeforeContentLoaded = `
Object.defineProperty(document, 'hidden', { value: false });
Object.defineProperty(document, 'visibilityState', { value: 'visible' });
document.addEventListener('visibilitychange', function(event) {
event.stopImmediatePropagation();
}, true);
`;
return (
<View style={styles.container}>
<WebView
source={{ uri: '' }}
injectedJavaScriptBeforeContentLoaded={injectedJavaScriptBeforeContentLoaded}
mediaPlaybackRequiresUserAction={false}
allowsInlineMediaPlayback={true}
javaScriptEnabled={true}
domStorageEnabled={true}
/>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
export default App;
最新文章
- 能跑安卓的锐龙3000C原来是它!热设计功耗低至4.5W
- visual c++ - MSVC errors out: undeclared identifier for SQL Server - Stack Overflow
- python - Problem of redirect when trying to authenticate user using supabase - Stack Overflow
- html - Audio tag working in Chrome but not Safari? - Stack Overflow
- R CatBoost support for incremental training - Stack Overflow
- python - Why does my plot have criss-crossing lines when I convert the index from string to datetime? - Stack Overflow
- linux - Zowe Config Error popping up on VSCODE? How may I fix this error? - Stack Overflow
- pytorch - Why can't my DDPG solve MountainCarContinuous-v0 - Stack Overflow
- mip sdk - Can you use the mip sdk to apply a mpip sensitivity label to a .json? - Stack Overflow
- rust - Basic bracket-lib example crashes with “unsafe precondition(s) violated: slice::from_raw_parts” - Stack Overflow
- javascript - Alphabetize options in a select list, retain event listeners - Stack Overflow
- node.js - I don't understand why I am getting a "no overload match for this call" error - Stack Overfl
- git - SourceTree - "This is not a valid source pathURL" error attempting to clone a GitHub repository - Stack
- testing - Cypress does not load static fonts - Stack Overflow
- Need to find a way to change a library (SO file) without reinstalling an application in Android 13 on rooted device. Permission
- glsl - How do I create Uniform Object Buffers in Qt3d with PySide 6? - Stack Overflow
- javascript - How can I create hyperlinkOrPicture column types on SharePoint Lists with Microsoft Graph API or Sharepoint API? -