Run assertions directly in browser context in Playwright

I would like to test some apis which are tied directly into browser and not necessary have UI representation.

Simpliest test beeing something like:

test("creates Image element", async ({ page }) => {
  await page.goto(`http://localhost:3333/e2e/assets/Dynamic.spec.html`);

  const img = new Image();
  const asset = new DynamicAsset(img);

  expect(asset.element()).toEqual(img);
});

When using cypress, all the tests are run in browser context. What would work.

But in playwright following error occurs:

ReferenceError: Image is not defined

    at file:///Users/tomche/development/frontendara/amandes/e2e/assets/Dynamic.spec.js:6:15

And if using page.evaluate like:

  await page.evaluate(() => {
    const img = new Image();
    const asset = new DynamicAsset(img);

    expect(asset.element()).toEqual(img);
  });

Error is:

page.evaluate: ReferenceError: expect is not defined

Which is happening since code evaluated in browser context doesn’t have imports from upper scope.

Documentation seems to mention only things which are serialisable, but this code needs complex things to be verified which are not really mockable in node or serilasible.

So is there a way to run assertions inside the browser similar to cypress/karma etc.?

How can i overlay audio with video?

So i wanted to overlay 2 files so they played together using html video controls , this is because the file it too large to fit in one whole bit . I wanted to add two videos , one with audio but a black screen and one with video but no audio and overlay.

I tried

<!DOCTYPE html>
<html>
<body>

<h1>The video element</h1>

<video width="320" height="240" controls>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>

</body>
</html>

but it doesn’t actually play them together on further testing.

does anyone know how i could link them together so that when it pause both of the files pause, unpause and can be skipped to a certain timestamp. I am unsure if this is accomplish and if it is possible using java-script, can you please show me how!

Discord.JS V13 – Slash Command Options “TypeError: command.options?.map is not a function”

I made a support for options in slash command in Discord.JS. But it gets TypeError continuously.

And if i delete options and option property from the script, it just ignores choices and returns a command like form of this:

Image

command.json’s fragment that causes error:
(Only option causes this error. Other type won’t cause error.)

{
    "commands": [
       {
            "GuildId": "global",
            "data": {
                "name": "Loop",
                "type": 1,
                "description": "Setup loop mode.",
                "options":{
                    "option":[
                "choices": {
                    {
                        "name": "Off",
                        "value": "QueueRepeatMode.OFF"
                    },
                    {
                        "name": "Play One Song",
                        "value": "QueueRepeatMode.TRACK"
                    },
                    {
                        "name": "Every Queue",
                        "value": "QueueRepeatMode.QUEUE"
                    },
                    {
                        "name": "Autoplay",
                        "value": "QueueRepeatMode.AUTOPLAY"
                    }
                    }
                ]
                },
                "defaultPermission": true
            }
        }
]
}

index.js :


    const token = "MY_TOKEN";
    const { Client } = require('discord.js');
    
    const client = new Client({ intents: parseInt("10111111111111111", 2) });
    
    client.login(token).then(async () => {
        for (data of await client.application?.commands.fetch()) {
            await client.application?.commands.delete(data[0]);
        }
        console.log('[ℹ️ INFO] Remaining CMD is deleting');
        const { commands } = require('./commands.json');
        for (command of commands) {
            console.log('[ℹ️ INFO] Slash CMD is registering: ',command.data.name);
            let AppCommand = null;
            if (command.GuildId == 'global')
                AppCommand = await client.application?.commands.create(command.data);
            else AppCommand = await client.application?.commands.create(command.data, command.GuildId);
            if ('permissions' in command) {
                const permissions = command.permissions;
                await AppCommand.permissions.add({ permissions });
            }
        }
        console.log('[ℹ️ INFO] Slash CMD was registered.');
    });

Error:

/workspaces/askk6-discord/node_modules/discord.js/src/managers/ApplicationCommandManager.js:211
      options: command.options?.map(o => ApplicationCommand.transformOption(o)),
                                ^

TypeError: command.options?.map is not a function
    at Function.transformCommand (/workspaces/askk6-discord/node_modules/discord.js/src/managers/ApplicationCommandManager.js:211:33)
    at ApplicationCommandManager.create (/workspaces/askk6-discord/node_modules/discord.js/src/managers/ApplicationCommandManager.js:118:30)
    at /workspaces/askk6-discord/manual-register.js:18:65
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Sellection in contentEditable collaps as soon as I click a button

As can be seen bellow, instead of <button> or <input> I have used <div> to create my UI buttons. Now the problem is as soon as I click any of the buttons, the selection in the edit area (a contenEditable <div>) collaps.

Interesetingly if I use <button> instead of <div> to create my UI buttons, everything works like a charm. I have seen this question asked many times before on stackoverflow, but they all use <button>. Any idea?

enter image description here

Reshow contents on page reload History.js

I’ve been trying history.js and it works well. However, when I reload the page it says not found. Here is the code:

<body>
MAIN NAVIGATION
<a href="#" link="hello">hello page</a>
<div id="mydiv"></div>
<script>
    $("a").click(function() {
        var page = $(this).attr("link");
        history.pushState(null, null, page)
        $("#mydiv").load(page + ".html");

    });
</script>

Referencing TailwindCSS config from JavaScript in SvelteKit

I’m using SvelteKit, which uses Vite and the setup instructions calls for CommonJS config files:
https://tailwindcss.com/docs/guides/sveltekit

However, the guide for referencing the configuration in JavaScript requires ESM.
https://tailwindcss.com/docs/configuration#referencing-in-java-script

Attempting to change the tailwind.config.cjs to ESM doesn’t work (I get errors from other libraries trying to require() it as CJS).

Does anyone know how I can either get a working ESM tailwind.config.js in SvelteKit or a different better method to reference the tailwind config?

Is there a way to call an event listener?

In a project, I am trying to make a button work based on the events happening in an event listener, so whenever the button has clicked the events in that event listener is supposed to execute, so is there a way to add <button onclick="EVENT LISTENER"></button>??

How to change name new creating folder with the subfolders

i want creating new folder with new name from cell in the sheet, and i want copy to this folder files and folders with the sourcedestiny.

Could you help me to solve my problem.

It is possible change name newFolder witout change name folders and subfolders- after his creating?

function copyFolderass() {
   const sourceFolder = DriveApp.getFolderById('');
  const destinyFolder = DriveApp.getFolderById('');
  copyFolder(sourceFolder, destinyFolder);
}

function copyFolderContents(source, target) {
  const filesIterator = source.getFiles();
  while (filesIterator.hasNext()) {
  const file = filesIterator.next();
  file.makeCopy(file.getName(), target);
  }
}

function copyFolder(sourceFolder, destinyFolder) {
   var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("nameFile");
   var name = ss.getRange("F4").getValue();

  const newFolder = destinyFolder.createFolder(sourceFolder.getName()); 
  copyFolderContents(sourceFolder, newFolder);
  const foldersIterator = sourceFolder.getFolders();
  while (foldersIterator.hasNext()) {
    const folder = foldersIterator.next();
    copyFolder(folder, newFolder);
  }
}

How can I track changes on a webpage?

I’m looking to build a solution that will track a page, then alert me when a certain keyword is added.

For example, track https://stackoverflow.com/jobs/companies and check once a day to see if “Google” is added to the page. It would make the most sense from a user’s perspective for this to be a chrome extension.

It’s a project I want to build and I’m a relatively new developer who has learned js/react so far. This will be my first project on my own. I’m trying to break it down by features/tasks and not sure how to do this part. Thank you!

Object Properties in .js files not properly executing in HTML

I’m very new to JavaScript (I have very limited Python experience as well) and am trying to find a simple way to call an object property from another .js file I have feeding into my HTML base file.

Snip of flowers.js

const rose = {name:'Rose', color:'Red', pic:'Rose.png'};

Snip of HTML base file

<html>
<head> 
<script src="flowers.js"></script>
</head>
<body>
<img id='flowerOne' src=rose.pic style='width:100px'>
</body>
</html>

This works fine if I paste the image reference in directly (“Rose.png” within img src) but not if I write out rose.pic, which theoretically has the exact same reference? I’ve managed to get .js file functions to work just fine, it just seems to be calling object properties where I’m struggling.

I’m probably not understanding something – any help is appreciated. Thank you!

A-Frame: post-processing attempt works on desktop, fails in VR

I am attempting a simple approach to postprocessing in A-Frame (without using the three.js classes EffectComposer, etc., for simplicity). The approach seems standard:

  • create a new render target
  • render the scene into the target’s texture
  • create a secondary scene containing a single quad, with a custom shader material that alters that texture in some way
  • use an orthographic camera to render the secondary scene into the main window

I have set this up with an A-Frame component as follows (with the goal of working in VR, as seen by the code in the tick function):

AFRAME.registerComponent("color-shift", {
    init: function () 
    {
        // render the scene to this texture
        this.renderTarget0 = new THREE.WebGLRenderTarget(1024, 1024);
        this.renderTarget0.texture.magFilter = THREE.NearestFilter;
        this.renderTarget0.texture.minFilter = THREE.NearestFilter;
        this.renderTarget0.texture.generateMipmaps = false;

        let texture = this.renderTarget0.texture;

        let postMaterial = new THREE.ShaderMaterial( {

          uniforms: {
            tex: {type: "t", value: texture},
          },

          vertexShader: `
          varying vec2 vUv;
          void main() 
          {
              vUv = uv;
              gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
          }
          `,

          fragmentShader: `
          varying vec2 vUv;
          uniform sampler2D tex;
          void main() 
          {
              vec4 color = texture2D(tex, vUv);
              gl_FragColor = vec4(color.g, color.b, color.r, 1);
          }
          `
         });

        // separate scene #1 for texture post processing
        const quad = new THREE.Mesh(
            new THREE.PlaneGeometry(2, 2), postMaterial );

        this.rtScene = new THREE.Scene();
        this.rtScene.add(quad);
        this.rtCamera = new THREE.OrthographicCamera();
        this.rtCamera.position.z = 0.5;
    },

    tick: function(t, dt)
    {
       // store XR settings
       const renderer = this.el.sceneEl.renderer;
       const currentRenderTarget = renderer.getRenderTarget();
       const currentXrEnabled = renderer.xr.enabled;
       const currentShadowAutoUpdate = renderer.shadowMap.autoUpdate;

       // temporarily disable XR
       renderer.xr.enabled = false;
       renderer.shadowMap.autoUpdate = false;

       // apply post-processing effects to previously rendered target texture,
       //   displayed on a quad, rendered to screen
       renderer.setRenderTarget(null);
       renderer.render(this.rtScene, this.rtCamera);

       // re-enable XR
       renderer.xr.enabled = currentXrEnabled;
       renderer.shadowMap.autoUpdate = currentShadowAutoUpdate;
       
       // render scene onto a texture the next time it renders
       renderer.setRenderTarget(this.renderTarget0); 
    }
});

The complete source code is at: https://github.com/stemkoski/A-Frame-Examples/blob/master/post-processing-test.html and a live version is at https://stemkoski.github.io/A-Frame-Examples/post-processing-test.html.

This example works perfectly as expected on desktop, resulting in a hue shift, but when entering VR mode, the screen is completely black.

I am not sure why this happens; the details about how rendering in VR mode works are a little confusing to me. I think that in VR mode, the camera is actually an array of 2 perspective cameras. I thought that the renderer’s render method rendered the scene twice, once from each of these cameras, into a viewport that corresponds to half of a rendertarget texture, but I may very well be mistaken. I would like to capture the results of the render while in VR mode and then apply simple postprocessing to it, like in the shader above. How can I fix the code above to accomplish this?

Is there a way for a Chrome plugin to aggregate incoming Discord messages?

I’d like to write a simple Chrome plugin which will aggregate incoming Discord messages from the active Discord tab(s), but I’m not sure if it is at all possible to intercept said messages, or at least watch for changes in the Discord DOM.

Is there a way to grab incoming Discord messages on whatever tabs the plugin is running on?

Note: I know that this would be trivial by instead writing a bot, but I’d like the plugin to be usable on servers/channels that you don’t own as well, if at all possible.