i want to RUN a simple nodejs script which runs headful playwright in a linux RDP running xrdp with gnome as root , and i want to target a non root user's $DISPLAY
the goal is i don't want the rdp user to have access to the script so i place them in root session and i run the express server as root , and when i run it as root the rdp non root user would see the headful browser opening when he accesses the RDP in a client
below works when the non root user is running the express server
as root don't work i get the following error when i run it : Missing X server or $DISPLAY
i am i triggering the script with an http request
import playwright from 'playwright';
const data = exec(
"loginctl show-session $(loginctl -a show-user rdp | grep Display | sed 's/Display.//g') | grep Display | sed 's/Display.//g'",
);
if (data.stdout.length) {
process.env['DISPLAY'] = data.stdout.replace(/\n/g, ''); // sets the DISPLAY env to for say :10.0
}
(async () => {
// Setup
const browser = await playwright.chromium.launch({
headless:false
});
const page = await browser.newPage();
// The actual interesting bit
await page.goto('https://example.com/');
// Teardown
await browser.close();
})()