Skip to content

Commit

Permalink
AG-24824 explicitly set tab title for url updates of TabContext
Browse files Browse the repository at this point in the history
Merge in ADGUARD-FILTERS/tsurlfilter from fix/AG-24824 to master

Squashed commit of the following:

commit 76ebadd
Merge: a4b6b9f 8d8ebd2
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Fri Sep 8 16:33:46 2023 +0300

    Merge branch 'master' into fix/AG-24824

commit a4b6b9f
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Fri Sep 8 11:58:18 2023 +0300

    fix changelog

commit ecf5c63
Merge: fc24d20 b1e75f7
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Fri Sep 8 11:53:38 2023 +0300

    Merge branch 'master' into fix/AG-24824

commit fc24d20
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Thu Sep 7 14:11:50 2023 +0300

    use TabContext.isBrowserTab

commit 4b35f0c
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Wed Sep 6 12:41:22 2023 +0300

    use tabInfo better and tweak tests

commit 72d9fd2
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Tue Sep 5 21:39:09 2023 +0300

    use tabInfo to get title

commit 417eb0d
Merge: 23c4bbb ca37cf3
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Tue Sep 5 14:33:46 2023 +0300

    Merge branch 'master' into fix/AG-24824

commit 23c4bbb
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Mon Sep 4 17:14:36 2023 +0300

    add testcase

commit fa75941
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Mon Sep 4 17:06:28 2023 +0300

    update changelog

commit e9e12ec
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Mon Sep 4 17:02:15 2023 +0300

    explicitly set tab title for url updates in tabs-api
  • Loading branch information
stanislav-atr committed Sep 8, 2023
1 parent 8d8ebd2 commit 6567b41
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
8 changes: 7 additions & 1 deletion packages/tswebextension/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<!-- TODO: manually add compare links for version to the end of the file -->
<!-- e.g. [0.1.2]: https://github.com/AdguardTeam/tsurlfilter/compare/tswebextension-v0.1.1...tswebextension-v0.1.2 -->


## Unreleased

### Fixed
- Tab title is now correctly updated on url change when the document does not provide it itself
[#2428](https://github.com/AdguardTeam/AdguardBrowserExtension/issues/2428).

## [0.3.16] - 2023-09-05

### Fixed
- Do not apply cosmetic rules to extension pages while fallback processing
[#2459](https://github.com/AdguardTeam/AdguardBrowserExtension/issues/2459).


## [0.3.15] - 2023-09-05

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,21 @@ export class TabContext {
/**
* Updates tab info.
*
* @param changeInfo Tab change info.
* @param tabInfo Tab info.
*/
public updateTabInfo(changeInfo: Tabs.OnUpdatedChangeInfoType): void {
this.info = Object.assign(this.info, changeInfo);
public updateTabInfo(tabInfo: TabInfo): void {
this.info = Object.assign(this.info, tabInfo);

// If the tab was updated it means that it wasn't used to send requests in the background.
this.isSyntheticTab = false;

// Update main frame data when we navigate to another page with document request caching enabled.
if (changeInfo.url) {
if (tabInfo.url) {
// Get current main frame.
const frame = this.frames.get(MAIN_FRAME_ID);

// If main frame url is the same as request url, do nothing.
if (frame?.url === changeInfo.url) {
if (frame?.url === tabInfo.url) {
return;
}

Expand All @@ -98,13 +98,13 @@ export class TabContext {
this.isDocumentRequestCached = true;

// Update main frame data.
this.handleMainFrameRequest(changeInfo.url);
this.handleMainFrameRequest(tabInfo.url);
}

// When the cached page is reloaded, we need to manually update
// the main frame rule for correct document-level rule processing.
if (!changeInfo.url
&& changeInfo.status === 'loading'
if (!tabInfo.url
&& tabInfo.status === 'loading'
&& this.isDocumentRequestCached
&& this.info.url) {
this.handleMainFrameRequest(this.info.url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { CosmeticResult, MatchingResult, NetworkRule } from '@adguard/tsurl

import { EventChannel } from '../../../common/utils/channels';
import type { DocumentApi } from '../document-api';
import { FrameRequestContext, TabContext } from './tab-context';
import { FrameRequestContext, TabContext, type TabInfo } from './tab-context';
import { type Frame, MAIN_FRAME_ID } from './frame';

/**
Expand Down Expand Up @@ -325,12 +325,15 @@ export class TabsApi {
*
* @param tabId Tab ID.
* @param changeInfo Tab change info.
* @param tabInfo Tab info.
*/
private handleTabUpdate(tabId: number, changeInfo: Tabs.OnUpdatedChangeInfoType): void {
private handleTabUpdate(tabId: number, changeInfo: Tabs.OnUpdatedChangeInfoType, tabInfo: Tabs.Tab): void {
// TODO: we can ignore some events (favicon url update etc.)
const tabContext = this.context.get(tabId);
if (tabContext) {
tabContext.updateTabInfo(changeInfo);
if (TabContext.isBrowserTab(tabInfo)) {
tabContext.updateTabInfo(tabInfo);
}
this.onUpdate.dispatch(tabContext);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,37 +50,37 @@ describe('TabContext', () => {

describe('updateTabInfo method', () => {
it('should update tab info with the correct properties', () => {
const changeInfo = {
const newTabInfo = {
url: 'https://another.com',
status: 'loading',
};
} as TabInfo;

const expectedInfo = { ...tabInfo, ...changeInfo };
const expectedInfo = { ...tabInfo, ...newTabInfo };

tabContext.updateTabInfo(changeInfo);
tabContext.updateTabInfo(newTabInfo);

expect(tabContext.info).toEqual(expectedInfo);
expect(tabContext.info).toBe(tabInfo);
expect(tabContext.isSyntheticTab).toBe(false);
});

it('should handle cached document page initialization on tab update', () => {
const changeInfo = {
const newTabInfo = {
url: 'https://another.com',
status: 'loading',
};
} as TabInfo;

tabContext.updateTabInfo(changeInfo);
tabContext.updateTabInfo(newTabInfo);

expect(tabContext.isDocumentRequestCached).toBe(true);
expect(documentApi.matchFrame).toBeCalledWith(changeInfo.url);
expect(documentApi.matchFrame).toBeCalledWith(newTabInfo.url);
});

it('should handle cached document page relaod on tab update', () => {
const changeInfo = { status: 'loading' };
it('should handle cached document page reload on tab update', () => {
const newTabInfo = { status: 'loading' } as TabInfo;

tabContext.isDocumentRequestCached = true;
tabContext.updateTabInfo(changeInfo);
tabContext.updateTabInfo(newTabInfo);

expect(documentApi.matchFrame).toBeCalledWith(tabInfo.url);
});
Expand Down

0 comments on commit 6567b41

Please sign in to comment.