Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to execute 'requestFullscreen' on 'Element': API can only be initiated by a user gesture. #213

Open
Mr-Super-X opened this issue Jul 13, 2022 · 1 comment

Comments

@Mr-Super-X
Copy link

Mr-Super-X commented Jul 13, 2022

Every time you click, Report an error in vue3 + element plus

<template>
  <el-tooltip v-model="visible" :hide-after="0">
    <template #content>
      <span>{{ toolTipContent }}</span>
    </template>
    <v-svg-icon
      :icon-class="iconClass"
      @click="handleToggle"
      @mouseenter="visible = true"
      @mouseleave="visible = false"
    />
  </el-tooltip>
</template>

<script setup lang="ts">
import { ref, computed, onBeforeUnmount, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import screenfull from 'screenfull'

const visible = ref(false)
const isFullscreen = ref(false)
const toolTipContent = computed(() => (isFullscreen.value ? '退出全屏' : '全屏'))
const iconClass = computed(() => (isFullscreen.value ? 'exit-fullscreen' : 'fullscreen'))

const handleToggle = () => {
  if (!screenfull.isEnabled) {
    ElMessage({
      message: 'you browser can not work',
      type: 'warning',
    })
    return false
  }
  screenfull.toggle().catch(() => '')
}
const handleChange = () => {
  isFullscreen.value = screenfull.isFullscreen
}

onBeforeUnmount(() => {
  if (screenfull.isEnabled) {
    screenfull.off('change', handleChange)
  }
})

onMounted(() => {
  if (screenfull.isEnabled) {
    screenfull.on('change', handleChange)
  }
})
</script>
@gurvirbaraich
Copy link

There's no problem with the library, its the default browser behaviour that cannot be manipulated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants