This repository has been archived by the owner on Nov 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 954
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
open source the cookie monitoring plugin
Summary: This diffs adds an ios plugin to monitor the app's NSCookie storage Differential Revision: D56712794
- Loading branch information
1 parent
7cd9e2e
commit db07c5c
Showing
4 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
*/ | ||
|
||
import {DataTableColumn, createTablePlugin} from 'flipper-plugin'; | ||
|
||
type Row = { | ||
id: number; | ||
Name: string; | ||
Expires: string; | ||
Value: string; | ||
}; | ||
|
||
const columns: DataTableColumn<Row>[] = [ | ||
{ | ||
key: 'Name', | ||
width: 250, | ||
}, | ||
{ | ||
key: 'Expires', | ||
width: 250, | ||
}, | ||
{ | ||
key: 'Value', | ||
}, | ||
]; | ||
|
||
module.exports = createTablePlugin<Row>({ | ||
columns, | ||
key: 'id', | ||
method: 'addCookie', | ||
resetMethod: 'resetCookies', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"$schema": "https://fbflipper.com/schemas/plugin-package/v2.json", | ||
"name": "flipper-plugin-cookies", | ||
"id": "cookies", | ||
"pluginType": "client", | ||
"version": "0.0.0", | ||
"flipperBundlerEntry": "index.tsx", | ||
"main": "dist/bundle.js", | ||
"license": "MIT", | ||
"title": "Cookies", | ||
"icon": "apps", | ||
"keywords": [ | ||
"flipper-plugin", | ||
"cookies" | ||
], | ||
"description": "Flipper plugin to monitor NSHTTPCookieStorage", | ||
"peerDependencies": { | ||
"flipper-plugin": "*", | ||
"antd": "*", | ||
"react": "*", | ||
"react-dom": "*", | ||
"@emotion/styled": "*", | ||
"@ant-design/icons": "*", | ||
"@types/react": "*", | ||
"@types/react-dom": "*", | ||
"@types/node": "*" | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...lugins/FlipperKitCookiesPlugin/FlipperKitCookiesPlugin/Exported/FlipperKitCookiesPlugin.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#ifdef FB_SONARKIT_ENABLED | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import <FlipperKit/FlipperPlugin.h> | ||
|
||
@interface FlipperKitCookiesPlugin : NSObject<FlipperPlugin> | ||
|
||
@end | ||
|
||
#endif |
71 changes: 71 additions & 0 deletions
71
...ugins/FlipperKitCookiesPlugin/FlipperKitCookiesPlugin/Exported/FlipperKitCookiesPlugin.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#ifdef FB_SONARKIT_ENABLED | ||
|
||
#import "FlipperKitCookiesPlugin.h" | ||
#import <FlipperKit/FlipperClient.h> | ||
#import <FlipperKit/FlipperConnection.h> | ||
#import <FlipperKit/FlipperResponder.h> | ||
#import "Plugins.h" | ||
|
||
@implementation FlipperKitCookiesPlugin { | ||
id<FlipperConnection> _connection; | ||
} | ||
|
||
- (NSString*)identifier { | ||
return @"cookies"; | ||
} | ||
|
||
- (void)didConnect:(id<FlipperConnection>)connection { | ||
_connection = connection; | ||
[self _sendCookies]; | ||
|
||
[[NSNotificationCenter defaultCenter] | ||
addObserver:self | ||
selector:@selector(onCookieStorageChange:) | ||
name:NSHTTPCookieManagerCookiesChangedNotification | ||
object:nil]; | ||
} | ||
|
||
- (void)didDisconnect { | ||
[[NSNotificationCenter defaultCenter] removeObserver:self]; | ||
_connection = nil; | ||
} | ||
|
||
#pragma mark - cookie storage observer | ||
|
||
- (void)onCookieStorageChange:(NSNotification*)notification { | ||
[self _sendCookies]; | ||
} | ||
|
||
#pragma mark - helper | ||
|
||
- (void)_sendCookies { | ||
[_connection send:@"resetCookies" withParams:@{}]; | ||
|
||
NSInteger i = 1; | ||
NSArray<NSHTTPCookie*>* _Nullable cookies = | ||
[[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies] copy]; | ||
for (NSHTTPCookie* cookie in cookies) { | ||
NSMutableDictionary<NSString*, id>* dict = [NSMutableDictionary dictionary]; | ||
dict[@"id"] = @(i); | ||
dict[@"Name"] = cookie.name; | ||
dict[@"Expires"] = cookie.expiresDate.description; | ||
dict[@"Value"] = cookie.value; | ||
[_connection send:@"addCookie" withParams:dict]; | ||
i++; | ||
} | ||
} | ||
|
||
@end | ||
|
||
void FlipperKitCookiesPluginInit(FlipperClient* client) { | ||
[client addPlugin:[FlipperKitCookiesPlugin new]]; | ||
} | ||
|
||
#endif |