
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
A comprehensive wake lock library for preventing device sleep with intelligent fallback strategies and exceptional performance
A comprehensive, framework-agnostic TypeScript library for preventing device sleep with intelligent fallback strategies, battery optimization, and performance monitoring.
# Using npm
npm install awake-lock
# Using pnpm (recommended)
pnpm add awake-lock
# Using yarn
yarn add awake-lock
import { WakeLock } from 'awake-lock';
const wakeLock = new WakeLock();
// Request wake lock
const sentinel = await wakeLock.request('screen');
// Release wake lock
await wakeLock.release();
import { useWakeLock } from 'awake-lock';
function VideoPlayer() {
const { isActive, request, release, isSupported } = useWakeLock({
onEnabled: () => console.log('Wake lock enabled'),
onDisabled: () => console.log('Wake lock disabled'),
});
return (
<div>
{isSupported ? (
<button onClick={() => (isActive ? release() : request())}>
{isActive ? 'Release' : 'Keep Screen On'}
</button>
) : (
<p>Wake lock not supported</p>
)}
</div>
);
}
<template>
<div>
<button @click="toggle" :disabled="!isSupported">
{{ isActive ? 'Release' : 'Keep Screen On' }}
</button>
</div>
</template>
<script setup>
import { useWakeLock } from 'awake-lock';
const { isActive, request, release, isSupported } = useWakeLock({
onEnabled: () => console.log('Wake lock enabled'),
onDisabled: () => console.log('Wake lock disabled'),
});
const toggle = () => {
isActive.value ? release() : request();
};
</script>
import { Component, OnInit } from '@angular/core';
import { WakeLockService } from 'awake-lock';
@Component({
selector: 'app-video-player',
template: `
<button (click)="toggle()" [disabled]="!isSupported">
{{ (isActive$ | async) ? 'Release' : 'Keep Screen On' }}
</button>
`,
})
export class VideoPlayerComponent implements OnInit {
isActive$ = this.wakeLockService.isActive$;
isSupported = this.wakeLockService.isSupported();
constructor(private wakeLockService: WakeLockService) {}
async toggle() {
const isActive = await this.isActive$.pipe(take(1)).toPromise();
if (isActive) {
await this.wakeLockService.release();
} else {
await this.wakeLockService.request();
}
}
}
class WakeLock extends EventEmitter {
constructor(options?: WakeLockOptions);
request(type: 'screen' | 'system', options?: RequestOptions): Promise<WakeLockSentinel>;
release(): Promise<void>;
isSupported(): boolean;
getStatus(): WakeLockStatus;
getSupportedStrategies(): string[];
checkPermissions(type: WakeLockType): Promise<PermissionState | null>;
destroy(): void;
}
interface WakeLockOptions {
strategies?: FallbackStrategy[]; // Custom fallback strategies
debug?: boolean; // Enable debug logging
batteryOptimization?: boolean; // Auto-release on low battery
performanceMonitoring?: boolean; // Track performance metrics
passive?: boolean; // Fail silently on permission prompts
}
interface RequestOptions {
passive?: boolean; // Override global passive setting
timeout?: number; // Request timeout in milliseconds
retryAttempts?: number; // Number of retry attempts
signal?: AbortSignal; // AbortController signal
}
Prevent disruptive permission prompts:
const wakeLock = new WakeLock({ passive: true });
// Will fail silently if permission prompt would be shown
await wakeLock.request('screen', { passive: true });
const wakeLock = new WakeLock({
batteryOptimization: true,
performanceMonitoring: true,
});
wakeLock.on('battery-change', ({ level, charging }) => {
console.log(`Battery: ${level * 100}%, Charging: ${charging}`);
});
wakeLock.on('performance', metrics => {
console.log('CPU Usage:', metrics.cpuUsage);
console.log('Memory Usage:', metrics.memoryUsage);
});
class CustomStrategy implements FallbackStrategy {
name = 'custom-strategy';
priority = 5;
isSupported(): boolean {
return /* your support detection */;
}
async request(type: WakeLockType): Promise<WakeLockSentinel> {
// Your implementation
}
}
const wakeLock = new WakeLock({
strategies: [new CustomStrategy()],
});
wakeLock.on('enabled', ({ type, strategy }) => {
console.log(`Wake lock enabled: ${type} via ${strategy}`);
});
wakeLock.on('disabled', ({ type, reason }) => {
console.log(`Wake lock disabled: ${type} (${reason})`);
});
wakeLock.on('error', ({ error, strategy }) => {
console.error(`Wake lock error in ${strategy}:`, error);
});
wakeLock.on('fallback', ({ from, to, reason }) => {
console.log(`Fallback from ${from} to ${to}: ${reason}`);
});
// Basic usage
const { isActive, request, release } = useWakeLock();
// With auto-request
const wakeLock = useWakeLock({
autoRequest: true,
type: 'screen'
});
// With context
<WakeLockProvider options={{ debug: true }}>
<App />
</WakeLockProvider>
// Composable
const { isActive, request, release } = useWakeLock();
// Plugin
app.use(WakeLockPlugin, { debug: true });
// Directive
<div v-wake-lock="{ autoRequest: true }">
Video content
</div>
// Service injection
constructor(private wakeLockService: WakeLockService) {}
// Module
@NgModule({
imports: [WakeLockModule],
providers: [
...provideWakeLock({ debug: true })
]
})
// Directive
<div wakeLock [wakeLockAutoRequest]="true">
Video content
</div>
| Browser | Screen Wake Lock API | Video Fallback | Audio Fallback | Timer Fallback |
|---|---|---|---|---|
| Chrome 84+ | ✅ | ✅ | ✅ | ✅ |
| Edge 84+ | ✅ | ✅ | ✅ | ✅ |
| Safari 16.4+ | ✅ | ✅ | ✅ | ✅ |
| Safari < 16.4 | ❌ | ✅ | ✅ | ✅ |
| Firefox | ❌ | ✅ | ✅ | ✅ |
| Mobile Safari | ❌ | ✅ | ✅ | ✅ |
The library includes a comprehensive test suite with 25/25 tests passing using Vitest:
# Run tests
pnpm test
# Run tests in watch mode
pnpm run test:watch
# Run tests with UI
pnpm run test:ui
# Clone repository
git clone https://github.com/Emmanuelnoi/awake-lock.git
# Install dependencies (using pnpm)
pnpm install
# Run development build with watch mode
pnpm run dev
# Run tests
pnpm test
# Build library
pnpm run build
# Run linting
pnpm run lint
# Type checking
pnpm run typecheck
# Format code
pnpm run format
Major Features:
Technical Improvements:
MIT License - see LICENSE file for details.
Made by Emmanuel Noi
FAQs
A comprehensive wake lock library for preventing device sleep with intelligent fallback strategies and exceptional performance
We found that awake-lock demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.