Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open source the cookie monitoring plugin #5591

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions desktop/plugins/public/cookies/index.tsx
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',
});
28 changes: 28 additions & 0 deletions desktop/plugins/public/cookies/package.json
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": "*"
}
}
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
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
Loading