fix(logs): handle missing clipboard API in non-HTTPS contexts (#8942)
This commit is contained in:
commit
e9f62f1fa4
3 changed files with 59 additions and 4 deletions
|
|
@ -186,8 +186,15 @@
|
||||||
copyLogs() {
|
copyLogs() {
|
||||||
const content = this.collectVisibleLogs();
|
const content = this.collectVisibleLogs();
|
||||||
if (!content) return;
|
if (!content) return;
|
||||||
navigator.clipboard.writeText(content);
|
if (!navigator.clipboard?.writeText) {
|
||||||
Livewire.dispatch('success', ['Logs copied to clipboard.']);
|
Livewire.dispatch('error', ['Clipboard is not available. Please use HTTPS or localhost.']);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
navigator.clipboard?.writeText(content).then(() => {
|
||||||
|
Livewire.dispatch('success', ['Logs copied to clipboard.']);
|
||||||
|
}).catch(() => {
|
||||||
|
Livewire.dispatch('error', ['Failed to copy logs to clipboard.']);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
downloadLogs() {
|
downloadLogs() {
|
||||||
const content = this.collectVisibleLogs();
|
const content = this.collectVisibleLogs();
|
||||||
|
|
|
||||||
|
|
@ -346,8 +346,17 @@ class="p-1 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-
|
||||||
<button
|
<button
|
||||||
x-on:click="
|
x-on:click="
|
||||||
$wire.copyLogs().then(logs => {
|
$wire.copyLogs().then(logs => {
|
||||||
navigator.clipboard.writeText(logs);
|
if (!navigator.clipboard?.writeText) {
|
||||||
Livewire.dispatch('success', ['Logs copied to clipboard.']);
|
Livewire.dispatch('error', ['Clipboard is not available. Please use HTTPS or localhost.']);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
navigator.clipboard.writeText(logs).then(() => {
|
||||||
|
Livewire.dispatch('success', ['Logs copied to clipboard.']);
|
||||||
|
}).catch(() => {
|
||||||
|
Livewire.dispatch('error', ['Failed to copy logs to clipboard.']);
|
||||||
|
});
|
||||||
|
}).catch(() => {
|
||||||
|
Livewire.dispatch('error', ['Failed to prepare logs for clipboard.']);
|
||||||
});
|
});
|
||||||
"
|
"
|
||||||
title="Copy Logs"
|
title="Copy Logs"
|
||||||
|
|
|
||||||
39
tests/Feature/LogClipboardHandlerTest.php
Normal file
39
tests/Feature/LogClipboardHandlerTest.php
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
function bladeView(string $path): string
|
||||||
|
{
|
||||||
|
return file_get_contents(base_path($path));
|
||||||
|
}
|
||||||
|
|
||||||
|
it('guards deployment log clipboard writes and reports promise failures', function () {
|
||||||
|
$view = bladeView('resources/views/livewire/project/application/deployment/show.blade.php');
|
||||||
|
|
||||||
|
expect($view)
|
||||||
|
->toContain('copyLogs()')
|
||||||
|
->toContain('navigator.clipboard?.writeText')
|
||||||
|
->toContain("Livewire.dispatch('error', ['Clipboard is not available. Please use HTTPS or localhost.']);")
|
||||||
|
->toContain("Livewire.dispatch('error', ['Failed to copy logs to clipboard.']);")
|
||||||
|
->toContain("Livewire.dispatch('success', ['Logs copied to clipboard.']);");
|
||||||
|
|
||||||
|
expect(Str::between($view, 'copyLogs() {', 'downloadLogs()'))
|
||||||
|
->toContain('navigator.clipboard?.writeText(content).then(() =>')
|
||||||
|
->not->toContain("navigator.clipboard.writeText(content);\n Livewire.dispatch('success'");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('guards shared log clipboard writes and handles Livewire preparation failures', function () {
|
||||||
|
$view = bladeView('resources/views/livewire/project/shared/get-logs.blade.php');
|
||||||
|
|
||||||
|
expect($view)
|
||||||
|
->toContain('navigator.clipboard?.writeText')
|
||||||
|
->toContain("Livewire.dispatch('error', ['Clipboard is not available. Please use HTTPS or localhost.']);")
|
||||||
|
->toContain("Livewire.dispatch('error', ['Failed to copy logs to clipboard.']);")
|
||||||
|
->toContain("Livewire.dispatch('error', ['Failed to prepare logs for clipboard.']);")
|
||||||
|
->toContain("Livewire.dispatch('success', ['Logs copied to clipboard.']);");
|
||||||
|
|
||||||
|
expect($view)
|
||||||
|
->toContain('$wire.copyLogs().then(logs =>')
|
||||||
|
->toContain('}).catch(() => {')
|
||||||
|
->not->toContain('navigator.clipboard.writeText(logs);');
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue