How to get around mBlock IDE's sandbox? (location.href & location.pathname)


#1

Hi,
I am doing an extension for mBlock that allows the mBlockers’ scripts to discuss together on the same lounge (online talking), but the probleme is that if A connect to the “Hello” lounge, then “B” can also join the same room using another script.

So I would be able to access the author name, or maybe the script name, to make the lounges specific to the author or script (to make one lounge (e.g. GlobalLounge) per author or script).

The location.pathname and location.href variables are actually modified, and are not the same between to pages from a same script.

Thanks for your help!

EDIT :

With the advice of @Best_codes (thanks to you) I would get the attention of @makeblock.lindingxin. Thanks for your answers!


#2

I’m not exactly sure how I would help you, but you could mention @makeblock.lindingxin and other team members to get their attention!

Thanks for your time,
Best_codes


#3

Who are they? I am 17 years old and am really not often here


#4

They are the makeblock official team members. Because they are normally busy, it can sometimes take months :slightly_frowning_face: for them to respond. You could find the solution to your problem on w3schools, but I’m not sure.

Thanks for your time,
Best_codes


#5

I cannot find my answers on w3schools. It depends of how the mBlock platform has been build.

Thanks for the answer, I mention the team! :slight_smile:


#6

You’re welcome! I’m sorry I couldn’t help you, but maybe the team will! :slight_smile:


#7

No worries! You helped me telling the name of a team, it is a lot.


#8

I think it will be a while before they respond…


#9

It seems to be


#10

Maybe these sites could help (use the search on them):



https://webplatform.github.io/docs/apis/location/pathname/


#11

The location.pathname property is modified by the mBlock platform. I just want to get the author or the password name.

Try writing return document.location.pathname into a string block’s script and make the preview two times, you’ll see that the both contents are different.

Maybe they are different for href and not different from others scripts for pathname, I don’t remember.

I have tried saving the script into the extension premier to make sure that the script is same and it doesn’t change that the properties are always different.

But thanks a lot for your help


#12

I agree with @Best_codes - I highly recommend W3Schools online tutorials and references.

They are VERY useful.


#13

Yes I know, but my question depends in the mBlock platform. Try writing console.dir(self) in an mBlock script and in the broswer’s inspector console, you’ll see that mBlock’s platform is blocking some basic browser’s tools for security reasons.


#14

True. I wonder if there are ways to work around that?


#15

It is think to be sufficient, so I am sure that there is a way to get script or author name without working around. If there is a block called “user name”, I guess that some datas like that are not known by me, so maybe is there informations about the running script?


#16

@KakiIn The way to do this would be by using a Node.js API, which you would have to deploy on a website like Vercel or Heroku. You can always ask my AI about it here:

https://best-codes.zapier.app/

With Node.js, you could make your application require verification of any sort you liked, and easily POST / GET data with JS in the blocks for communication.


#17

But mBlock didn’t made something to provide informations like that? It seems weird…

After having tested, there is something strange with your ai :
1- firstly, it seems to not understand why I ask him. When I ask him for a Javascript programm, it provides me something really useless
2- and then, when I say it what is false, it answers with scratch blocks instead of javascript code
3- it seems not to understand what I am asking to him at the moment it is precise

But it is not so bad


#18

Thanks for your feedback? Can you provide screenshots or text examples of your input and its responses? Thank you!

Example:

Input:

How should I ask you questions about code?

Output:

When asking questions about code, it’s helpful to be as specific as possible. Here’s a guide on how to ask effective questions:

  1. Clearly state the problem: Begin by describing the problem you’re trying to solve or the specific task you want to accomplish with your code.

  2. Provide relevant code snippets: If you have already attempted to write code for the problem, share the relevant parts of your code. This helps me understand your approach and identify any potential issues.

  3. Describe the expected outcome: Explain what you expect the code to do or the desired result you want to achieve. Be as detailed as possible.

  4. Specify any error messages: If you encountered any error messages or unexpected behavior, include them in your question. This information can be crucial in understanding the issue.

  5. Mention the programming language and framework: Specify the programming language and framework you are using. This allows me to provide more accurate and relevant assistance.

  6. Ask specific questions: Break down your problem into smaller, specific questions. This helps me address each part more effectively and provide you with actionable guidance.

By following these steps, you can ensure that your questions are clear and concise, making it easier for me to understand your problem and provide you with the most helpful response.


#19

@KakiIn Here is an example:

Write a code for a Node.js server that would allow users to make accounts and send chat messages to specific chatroom ids.

Sure! Here’s an example code for a Node.js server that allows users to create accounts and send chat messages to specific chatroom IDs using Express.js and Socket.IO:

// Import required packages
const express = require('express');
const http = require('http');
const socketIO = require('socket.io');

// Create the app and server
const app = express();
const server = http.createServer(app);
const io = socketIO(server);

// Store user accounts and chat messages
const users = {};
const chatrooms = {};

// Handle new socket connections
io.on('connection', (socket) => {
  // Handle user registration
  socket.on('register', (username) => {
    users[socket.id] = username;
    socket.emit('registered', username);
  });

  // Handle joining a chatroom
  socket.on('join', (chatroomId) => {
    socket.join(chatroomId);
  });

  // Handle chat messages
  socket.on('message', (data) => {
    const { chatroomId, message } = data;
    const username = users[socket.id];
    const chatroom = chatrooms[chatroomId];
    
    if (username && chatroom) {
      const chatMessage = {
        username,
        message,
        timestamp: new Date().getTime()
      };
      
      chatroom.push(chatMessage);
      io.to(chatroomId).emit('message', chatMessage);
    }
  });

  // Handle disconnection
  socket.on('disconnect', () => {
    delete users[socket.id];
  });
});

// Start the server
const port = process.env.PORT || 3000;
server.listen(port, () => {
  console.log(`Server is running on port ${port}`);
});

This code uses the Express.js framework to handle HTTP requests and Socket.IO for real-time communication. It provides functionality for user registration, joining chatrooms, and sending chat messages.

To use this server, you would need to create a frontend application that interacts with it using Socket.IO’s client-side library. You can emit events like ‘register’, ‘join’, and ‘message’ from the frontend to communicate with the server.

Note: This is a simplified example to give you an idea of how a server like this could be implemented. In a real application, you would need to add proper validation, authentication, and error handling.


#20

All that is written in this code, I can do it, the problem is for the script id

And after asking a little, your IA said me it is GPT3 (is it true? )

Else, the problem is that since I asked him if it knows mBlock, he considered I was using blocks, and not the extension code, even if I was precising him.