Избегайте мошенников, выдающих себя за службу поддержки. Мы никогда не попросим вас позвонить, отправить текстовое сообщение или поделиться личной информацией. Сообщайте о подозрительной активности, используя функцию «Пожаловаться».

Подробнее

Firefox reuses window object on same-origin iframe?

  • Нет ответов
  • 0 имеют эту проблему
  • 3 просмотра

I created a new iframe and added a new value in its contentWindow, and changed the src of the iframe like below.

``` (() => {

 const frame = document.createElement('iframe');
 document.body.appendChild(frame);
 frame.contentWindow.testASDF = 'TEST_VAR';
 frame.src = 'http://localhost:5500/test/iframe.html';
 setTimeout(() => console.log('testASDF: ', frame.contentWindow.testASDF), 3000); // I expect 'undefined', but 'TEST_VAR' printed.

})(); ```

I thought the 'testASDF' value would be gone after the iframe loaded the new src, but the value I set remaining even after the iframe loaded anew. In Chrome, it's not reproduced.

It only happens when I set a same-origin iframe src and modify the src synchronously with the line above. For example, the script below doesn't reproduce the problem.

``` (async () => {

 const sleep = (ms) => new Promise((res) => setTimeout(res, ms));
 const frame = document.createElement('iframe');
 document.body.appendChild(frame);
 frame.contentWindow.testASDF = 'TEST_VAR';
 await sleep(1); // asynchronous routine added
 frame.src = 'http://localhost:5500/test/test.html';
 setTimeout(() => console.log('testASDF: ', frame.contentWindow.testASDF), 3000);

})(); ```

Is this a bug or optimization of Firefox?

UA: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:137.0) Gecko/20100101 Firefox/137.0

I created a new iframe and added a new value in its contentWindow, and changed the src of the iframe like below. ``` (() => { const frame = document.createElement('iframe'); document.body.appendChild(frame); frame.contentWindow.testASDF = 'TEST_VAR'; frame.src = 'http://localhost:5500/test/iframe.html'; setTimeout(() => console.log('testASDF: ', frame.contentWindow.testASDF), 3000); // I expect 'undefined', but 'TEST_VAR' printed. })(); ``` I thought the 'testASDF' value would be gone after the iframe loaded the new src, but the value I set remaining even after the iframe loaded anew. In Chrome, it's not reproduced. It only happens when I set a same-origin iframe src and modify the src synchronously with the line above. For example, the script below doesn't reproduce the problem. ``` (async () => { const sleep = (ms) => new Promise((res) => setTimeout(res, ms)); const frame = document.createElement('iframe'); document.body.appendChild(frame); frame.contentWindow.testASDF = 'TEST_VAR'; await sleep(1); // asynchronous routine added frame.src = 'http://localhost:5500/test/test.html'; setTimeout(() => console.log('testASDF: ', frame.contentWindow.testASDF), 3000); })(); ``` Is this a bug or optimization of Firefox? UA: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:137.0) Gecko/20100101 Firefox/137.0
Приложенные скриншоты

Для ответа на сообщения вы должны войти в свою учётную запись. Пожалуйста, задайте новый вопрос, если у вас ещё нет учётной записи.